[問題] 請問關於readblock的疑問
在讀取檔案用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
→
03/12 13:37, , 1F
03/12 13:37, 1F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章