求助fileStream方法readbyte
protected void Button1_Click(object sender, EventArgs e)
{
FileInfo fi = new FileInfo(TextBox1.Text);
byte[] buffer=new byte[fi.Length];
int UploadContentLength=0;
using(FileStream fs=new FileStream(TextBox1.Text,FileMode.Open,FileAccess.Read))
{
while (UploadContentLength < fi.Length)
{
int bytes = 0;
//fs.Read(buffer, 0, 1);
bytes = fs.ReadByte();
UploadContentLength += bytes;
}
fs.Read(buffer, 0, buffer.Length);
}
string path = Server.MapPath(@"file");
FileStream fs2 = new FileStream(Path.Combine(path,fi.Name), FileMode.Create);
fs2.Write(buffer, 0, buffer.Length);
fs2.Close();
}
起着textBox1.Text为路径,我最终生成在服务器的txt文件中第一位内容没了
...全文
相关推荐
C# FileStream文件读写详解
对于大文件,使用ReadByte()和WriteByte()单个读写字节,或者使用ReadBytes()和WriteBytes()批量操作。
C#使用FileStream复制一个任意文件
FileStream提供了ReadByte()和WriteByte()方法来实现这个过程。ReadByte()方法读取一个字节并将其转换为整数值,如果读到文件的尽头,返回-1。
使用MemoryStream与FileStream
fsForRead.Read(bs, 0, 10);```**定位FileStream中的当前位置**可以使用`Seek`方法改变`FileStream`中的当前位置。
C#判断上传文件是否是图片以防止木马上传的方法
通过读取并比较文件头的字节,我们可以初步判断文件是否为图片:```csharpprivate bool IsPicture(string filePath){ try { FileStream fs =
C#如何判断两个文件是否完全相等
ReadByte(); } while ((file1Byte == file2Byte) && (file1Byte !


