作者miewQ (ICQ)
看板C_Sharp
标题[问题] 请问关於readblock的疑问
时间Sat Mar 11 15:35:51 2006
在读取档案用readblock,可以固定读出某个特定size。
但是我发现我遇到一个问题,我读出来的size与档案实际大小的size有差。
不知道为什麽会这样。
希望版上的大大能拨空指点一下 谢谢 ~~
例如我读取test.doc 档案大小是10752 bytes,但是我的程式读取出来只有 8965 bytes。
不知道为什麽会这样。
以下是我的程式码:
Stream filestream=null;
StreamReader readAdapter=null;
try
{
filestream=File.Open("test.doc",FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
}
catch (FileNotFoundException e)
{
Console.WriteLine(e.ToString());
return;
}
readAdapter=new StreamReader(filestream);
char []str=new char[1000];
int bytes=0;
int total=0;
do
{
bytes=readAdapter.ReadBlock(str,0,1000);
Console.WriteLine("{0}",bytes);
total+=bytes;
}
while(bytes==1000);
Console.WriteLine("total:{0} bytes",total);
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.131.51
1F:→ virdust2003:没试过,但我会改成这样 while(bytes != 0) 03/12 13:37