How to copy C # large files

Source: Internet
Author: User
Tags file copy

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.