当前位置:   article > 正文

C# FileStream实现大文件拷贝_c# 分包拷贝大文件

c# 分包拷贝大文件
private static void BigFileCopy(string source, string target)
{
    using (FileStream fsRead = File.OpenRead(source))
    {
        using (FileStream fsWrite = File.OpenWrite(target))
        {
            byte[] bytes = new byte[5 * 1024 * 1024];//定义5M空间
            int count = 0;
            while ((count = fsRead.Read(bytes, 0, bytes.Length)) > 0)
            {
                fsWrite.Write(bytes, 0, count);
                //fsRead.Position 表示已经读取的字节个数
                double per = (fsRead.Position / (double)fsRead.Length) * 100;
                Console.WriteLine($"{per:0.00}%");
            }
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/367396
推荐阅读
相关标签
  

闽ICP备14008679号