使用FileStream文件流实现大文件的拷贝

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Collections;
using System.Diagnostics;
using System.IO;
namespace 练习专用
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建读取文件的流
            using (FileStream fsReader = new FileStream(@"F:\毕设.rar", FileMode.Open))
            {
                //创建写入文件的流
                using (FileStream fsWriter = new FileStream(@"E:\毕设备份.rar", FileMode.OpenOrCreate))
                {
                    //创建一个5M的缓冲区
                    byte[] buffers = new byte[1024 * 1024 * 5];
                    int i = 0;
                    //文件读取到缓冲区
                    while ((i = fsReader.Read(buffers, 0, buffers.Length)) > 0)
                    {
                        //将缓冲区中内容写入fsWriter流
                        fsWriter.Write(buffers, 0, i);
                        //显示进度
                        long l = fsWriter.Length;
                        double proc = (double)l / fsReader.Length;
                        Console.WriteLine("拷贝进度{0}%", proc * 100);
                    }
                }
            }
        }
    }
}


你可能感兴趣的:(.NET)