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
                }
            }
        }
    }
}

 

posted @ 2016-10-24 15:31  墨水心2016  阅读(190)  评论(0编辑  收藏  举报