[問題] 請問關於readblock的疑問

看板C_Sharp (C#)作者 (ICQ)時間19年前 (2006/03/11 15:31), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/2 (看更多)
在讀取檔案用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
沒試過,但我會改成這樣 while(bytes != 0)
03/12 13:37, 1F
文章代碼(AID): #144dp038 (C_Sharp)
文章代碼(AID): #144dp038 (C_Sharp)