zoukankan      html  css  js  c++  java
  • c#大文件的拷贝

    using System.IO;
    
    namespace 数据流
    {
        class Demo2
        {
            private string _strSourcePath = @"D:httpd-2.4.37-o102q-x64-vc14-r2.zip";               //源文件路径
            private string _strTargetPath = @"E:httpd-2.4.37-o102q-x64-vc14-r2.zip";               //目标文件路径
    public void Test1()
            {
                if (File.Exists(_strSourcePath))
                {
                    //读取文件流
                    using (FileStream fsRead = new FileStream(_strSourcePath, FileMode.Open))
                    { 
                        //写文件流
                        using(FileStream fsWrite=new FileStream(_strTargetPath,FileMode.OpenOrCreate))
                        {
                            byte[] byArrarRead = new byte[1024 * 1024];
    
                            while (true)
                            {
                                int rsCount = fsRead.Read(byArrarRead, 0, byArrarRead.Length);
                                fsWrite.Write(byArrarRead, 0, rsCount);
    
                                if (rsCount < byArrarRead.Length)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("路径不存在");
                }
            }

    整体的思路:先获取到源文件和目标文件,我们选择流文件进行转移,就需要先读取数据流和写入数据流操作,然后分配内存地址,然后对二进制流进行真正的读写操作,直到全部读出为止。

    有人不让我喝鸡汤

  • 相关阅读:
    jquery height
    正则表达式的一点奇怪
    this和call
    ajax views
    史上变态的模块
    在php中有什么用
    localhost访问不了
    $.extend abc
    $.extend
    和人沟通的一个要点
  • 原文地址:https://www.cnblogs.com/Optimism/p/10446838.html
Copyright © 2011-2022 走看看