首页 > 其他 > 详细

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

时间:2014-04-23 09:53:51      阅读:564      评论:0      收藏:0      [点我收藏+]

1、循环读取啊,byte[]可以定义为1024或者2049等等,不要超过int的maxvalue就可以。
然后取出来操作完再去取。

 

bubuko.com,布布扣
 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();
bubuko.com,布布扣

 

2、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个字节

 

bubuko.com,布布扣
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();
                             }
bubuko.com,布布扣

 

 

filestream read方法 循环读取固定文件,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/frustrate2/p/3680471.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!