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