标签:creat pre project bre 申请 break string 大文件 copy
大文件拷贝原理:向内存申请1M空间,反复从源文件读取1M内容写入到目标文件,直到读完。
1 private void CopyBigFile() 2 { 3 string originalPath = @"E:\AdvanceCSharpProject\LearnCSharp\21.zip"; 4 string destPath = @"F:\BaiduNetdiskDownload\21.zip"; 5 //定义读文件流 6 using (FileStream fsr = new FileStream(originalPath, FileMode.Open)) 7 { 8 //定义写文件流 9 using (FileStream fsw = new FileStream(destPath, FileMode.OpenOrCreate)) 10 { 11 //申请1M内存空间 12 byte[] buffer = new byte[1024 * 1024]; 13 //无限循环中反复读写,直到读完写完 14 while(true) 15 { 16 int readCount = fsr.Read(buffer, 0, buffer.Length); 17 fsw.Write(buffer, 0, readCount); 18 if(readCount < buffer.Length) 19 { 20 break; 21 } 22 } 23 } 24 } 25 }
标签:creat pre project bre 申请 break string 大文件 copy
原文地址:https://www.cnblogs.com/blackteeth/p/10205044.html