惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
博客园 - 司徒正美
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
D
Docker
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
罗磊的独立博客
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
腾讯CDC
T
The Blog of Author Tim Ferriss
小众软件
小众软件
U
Unit 42
T
Tailwind CSS Blog

博客园 - 朱煜

项目经理与客户沟通的宜与忌 转 FileStream Read File c#描述异常处理语句try、catch、finally执行时的相互关系 C#计算文件的MD5值实例 C#获取文件MD5字符串 金旭亮老师的Scoekt编程摘要 Winfrom动态创建控件 多个文件合并成一个大文件后,无法打开,需要从以下几个方面找出问题? 腰围2尺1,2,3,4,5,6,7,8寸分别等于是多少厘米/英寸(对照表) 字符编码中的英文字母、汉字占有的字节长度。 Socket Programming in C#--Conclusion Socket Programming in C#--Server Side Socket Programming in C#--Multiple Sockets Socket Programming in C#--Getting Started Socket Programming in C#--Introduction C#中的is,as关键字 委托/事件与观察者模式 发布符合 .NET Framework 准则的事件(C# 编程指南) 在职研究生硕士学位证书查询和认证方式
filestream read方法 循环读取固定文件
朱煜 · 2014-04-22 · via 博客园 - 朱煜

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

 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();

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

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();
                             }