A breakpoint occurred in the file transfer

Source: Internet
Author: User

A: Find a larger file through the stream transmission, but to half of the time suddenly broke, make breakpoints, judge the source file and the file length is the same;

If the source file is larger than the local file size, you need to continue

If the source file is equal to the local file, then all passed, return this program;

If the source file equals zero, the file does not exist; It needs to start from scratch;

1 /**2 * breakpoint file making machine; professional manufacturing Breakpoints3          */4File src =NewFile ("d:\\ software \\FeiQ.exe");5File local =NewFile ("g:\\a\\" +src.getname ());6         7         Try {8InputStream in =NewFileInputStream (SRC);9OutputStream out =NewFileOutputStream (local);Ten              One             byte[] bs =New byte[1024]; A             LongOver =0; -              for(intlen = 0; (Len =in.read (BS))!=-1;) { -Out.write (BS, 0, Len); the                 //the file passed in half. Class breakpoints appear -Over =over+Len; -                 if(Over>src.length ()/2){ -System.out.println ("breakpoint appears"); +                      Break; -                 } +             } A out.close (); at in.close (); -}Catch(FileNotFoundException e) { - e.printstacktrace (); -}Catch(IOException e) { -             //TODO auto-generated Catch block - e.printstacktrace (); in}

1*/2File src =NewFile ("d:\\ software \\FeiQ.exe");3File local =NewFile ("g:/a/" +src.getname ());4         5System.out.println ("Source File size:" +src.length ());6         7         Longstart = 0;//file pointer start position8         9         if(src.length () = =local.length ()) {TenSystem.out.println ("File already exists, no replication required, end of program"); One             return; A}Else if(Local.length () ==0){ -SYSTEM.OUT.PRINTLN ("File does not exist, need to start from scratch"); -}Else if(Src.length () >local.length ()) { theSystem.out.println ("Breakpoint file, need to continue ..."); -Start =local.length (); -         } -          +         Try { -             //establishing a connection pipeline +InputStream in =NewFileInputStream (SRC); A              at             //output stream Append -OutputStream out =NewFileOutputStream (Local,true); -              -             byte[] bs =New byte[2048];  -  -             //set the input stream start position in In.skip (start); -SYSTEM.OUT.PRINTLN ("input stream start Position:" +start); to              +             //cyclic replication -              for(intLen=0 (Len=in.read (BS))!=-1; ){ theOut.write (BS, 0, Len); *             } $             Panax NotoginsengSYSTEM.OUT.PRINTLN ("Transfer End"); -              the             //release the resources, people go off the lights + out.close (); A in.close (); the              +}Catch(FileNotFoundException e) { - e.printstacktrace (); $}Catch(IOException e) { $E.printstacktrace ();

A breakpoint occurred in the file transfer

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.