📜  c# 读取大文件 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:03.054000             🧑  作者: Mango

代码示例2
int filesize = (new FileInfo(filePath)).Length;            
using (Stream sr = File.OpenRead(filePath))
{
  int maxchunk = 1024;
    for(long x = 0; x < totalChunk; x++ )
    {
        long LefttotalLegth = filesize - (x * maxchunk);
        long leghtcopy = Math.Min(maxchunk, LefttotalLegth);
        byte[] chunkbyte = new byte[leghtcopy];        
        sr.Read(chunkbyte, 0, chunkbyte.Length);
       //Do something after read. like write to file
    }                           
}