大文件拷贝练习

 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 }

 

posted @ 2014-02-12 10:03  无处安放的青春  阅读(198)  评论(0编辑  收藏  举报