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("路径不存在");
                }
            }

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

    有人不让我喝鸡汤

  • 相关阅读:
    python函数对象
    生成器表达式,列表推导式
    python转换excel成py文件
    Python处理excel表
    Go基础:接口相关
    JAVA03-输入和输出
    python6-while循环
    python5-字典
    自动化8-xpath
    网络学习day1-计算机网络基础
  • 原文地址:https://www.cnblogs.com/Optimism/p/10446838.html
Copyright © 2011-2022 走看看