Java copy a folder picture into another folder

Source: Internet
Author: User

import java.io.file;import java.io.fileinputstream;import java.io.fileoutputstream;import Java.util.Calendar; Public classSendserver {Private intnum =0;  Public voidprocess () {Calendar Calendar=calendar.getinstance (); String dir= Calendar.Get(calendar.year) +""+ gettimestring (Calendar.Get(Calendar.month) +""); String OldPath="/img2"+dir; String NewPath="/img5"+dir; Try {             while(true) {System. out. println ("Copy"+ OldPath +"Directory Start"); LongT1 =System.currenttimemillis (); Num=0;                                CopyFolder (OldPath, NewPath); Longt2 =System.currenttimemillis (); System. out. println ("Copy directory end, Time:"+ (T2-T1) +"MS, co-replication:"+ num +"file"); }        } Catch(Exception ex) {ex.printstacktrace (); }    }     Public voidCopyFolder (String OldPath, String newpath) {Try{File Mfile=NewFile (NewPath); if(!mfile. Exists ()) {                (NewFile (NewPath)). Mkdirs ();//Create a new folder if the folder does not exist} File a=NewFile (OldPath); string[] File=a.list (); File Temp=NULL;  for(inti =0; i < file.length; i++) {                if(Oldpath.endswith (file.separator)) {temp=NewFile (OldPath +File[i]); } Else{Temp=NewFile (OldPath + file.separator +File[i]); }                if(Temp.isfile ()) {String FileName= NewPath +"/"+(Temp.getname ()). ToString (); File testfile=NewFile (fileName); if(!testfile.exists ()) {FileInputStream input=NewFileInputStream (temp); FileOutputStream Output=NewFileOutputStream (fileName); byte[] B =New byte[1024x768*5]; intLen;  while(len = Input.read (b))! =-1) {Output.write (b,0, Len);                        } output.flush ();                        Output.close ();                        Input.close (); Num++; }                }                if(Temp.isdirectory ()) {//if it is a sub-folderCopyFolder (OldPath +"/"+ File[i], NewPath +"/"+File[i]); }            }        } Catch(Exception e) {System. out. println ("error Copying entire folder contents Operation");        E.printstacktrace (); }    }        Privatestring gettimestring (String time) {if(Time.length () <2){            return "0"+Time ; }        Else{            returnTime ; }    }}

Java copy a folder picture into another folder

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.