zoukankan      html  css  js  c++  java
  • 大文件拷贝练习

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.IO;
     6 
     7 namespace ConsoleApplication1
     8 {
     9     class Program
    10     {
    11         //delegate string works(int a,int b);
    12         static void Main(string[] args)
    13         {   
    14  #region 大文件拷贝
    15             FileHelper fh = new FileHelper("c:\error.txt", "d:\error.txt");
    16             //1.定义读文件的一个流
    17             using (FileStream fsRead = new FileStream(fh.Source, FileMode.Open))
    18             {
    19                 long totalLength = fsRead.Length;
    20                 long readPositon = fsRead.Position;
    21                 //2.定义一个读文件的缓存区
    22                 byte[] buffer = new byte[1024 * 1024 * 100];//一次读10m
    23                 //3.定义一个写文件的流
    24                 using(FileStream fsWrite = new FileStream(fh.target,FileMode.Create))
    25                 {
    26                     while (true)
    27                     {
    28                         int r = fsRead.Read(buffer, 0, buffer.Length);
    29                         if (r <= 0)//如果r<=0则说明读取完毕
    30                         {
    31                             break;
    32                         }
    33                         else
    34                         {
    35                             fsWrite.Write(buffer, 0, r);
    36                         }
    37                     }
    38                     
    39                 }
    40 
    41             }
    42             #endregion
    43             Console.WriteLine("读取完毕");
    44           Console.Read();
    45 
    46         }
    47    }
    48   public class FileHelper
    49     {
    50 
    51 
    52 
    53         public string Source { get; set; }
    54         public string target { get; set; }
    55         public  FileHelper(string source,string target)
    56         {
    57             this.Source = source;
    58             this.target = target;
    59         }
    60     }
    61 }
  • 相关阅读:
    dsu on tree
    bzoj3527 [Zjoi2014]力
    bzoj3527 [Zjoi2014]力
    114.遍历文件夹并批量修改文件名
    25.八皇后问题
    24.C语言最全排序方法小结(不断更新)
    112.备忘录设计模式
    110.文件搜索,系统大小获取,以及病毒行为
    109.vprintf vfprintf vscanf vfscanf
    108.sqllite3(C语言数据库库)详解
  • 原文地址:https://www.cnblogs.com/taomylife/p/3545435.html
Copyright © 2011-2022 走看看