How to copy read large files, perhaps confused a lot of people for a long time, this do not know how to do, it really makes people have a headache to crack, know that you just found that the original so simple, words do not say, straight into the ""
Static voidMain (string[] args) { BOOLB= CopyFile (@"D:\360 Secure Browser Download \2.avi",@"D:\360 Secure Browser Download \3.avi"); if(b) {Console.WriteLine ("Replication succeeded"); } Else{Console.WriteLine ("Replication Failed"); } console.readkey (); } /// <summary> ///Large file multiple copies file true: Copy succeeded false: Replication failed/// </summary> /// <param name= "Soucrepath" >Original file path</param> /// <param name= "TargetPath" >Copy destination file path</param> /// <returns></returns> Public Static BOOLCopyFile (stringSoucrepath,stringTargetPath) { Try { //read the copy file stream using(FileStream fsread =NewFileStream (Soucrepath, FileMode.Open, FileAccess.Read)) { //Write file copy stream using(FileStream fswrite =NewFileStream (TargetPath, FileMode.OpenOrCreate, FileAccess.Write)) { byte[] buffer =New byte[1024x768*1024x768*2];//2M per read//may be large file, to loop read, each read 2M while(true) { //data per read N: The actual data size to be read every time intn = fsread.read (buffer,0, buffer. Count ()); //If the n=0 indicates that the read data is empty, it has been read to the last, jumping out of the loop if(n = =0) { Break; } //actual data size to write per readFswrite.write (Buffer,0, N); } } } return true; } Catch(System.Exception ex) {return false; } }
is actually a method CopyFile (), call this method can be ...
How to copy C # large files