filestream read方法 循环读取固定文件

一、循环读取啊,byte[]能够定义为1024或者2049等等,不要超过int的maxvalue就能够。
而后取出来操做完再去取。web

 

 1  FileStream stream = new FileStream(path);
 2  byte[] writeData = new byte[8192];
 3   // Use the ReadAllBytesFromStream to read the stream.
 4   while (true)
 5   {
 6        int size = stream.Read(writeData, 0, writeData.Length);
 7        if (size > 0)
 8        {
 9             //你操做数据的代码
10       }
11        else
12        {
13             break;
14        }
15   }
16   stream.Close();

 

二、C# filestream.Read用在while循环有啥用?
FileStream fs = File.OpenRead("C:\\test.txt");
byte[] arr = new byte[100];
while (filestream.Read(arr, 0, arr.Length)>0)
{
Console.WriteLine(data.GetString(arr));
}
回答:循环读取文件,每次只读100个字节spa

 

string str = "C:\\test.txt";
                        if (!File.Exists(str))     ///检测文件是否存在
                           {
                                       MessageBox.Show("文件不存在,请查看客户端是否已经上传数据!");
                           }
                       else
                          {   
                                 FileStream fop = File.OpenRead(str);
                                 byte[] arr = new byte[1000];
                                 while (fop.Read(arr, 0, arr.Length) > 0)    ///这个循环会将文件全部的内容都读取出来
                                  {
                                  ClientSocket[1].Send(arr, 0, arr.Length,0);
                                  }
                                 fop.Close();
                             }
相关文章
相关标签/搜索