Filestream大文件的复制
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FileStreamCopy { class Program { static void Main(string[] args) { string readpath = @"F:\1.txt"; string newpath = @"F:\2.txt"; using (Stream inStream = new FileStream(readpath, FileMode.Open)) using (Stream outStream = new FileStream(newpath, FileMode.Create)) { byte[] bytes = new byte[1024*1024]; //缓存区的大小,太小降低速度;过大占用内存 int len; while ((len = inStream.Read(bytes, 0, bytes.Length)) > 0) { outStream.Write(bytes, 0, len);//类似于GetString } } } } }