File copy
Public Static voidCopyFile (String OldPath, String NewPath)throwsIOException {FileInputStream in=NULL; FileOutputStream out=NULL; Try{File OldFile=NewFile (OldPath); File File=NewFile (NewPath); Inch=NewFileInputStream (OldFile); out=Newfileoutputstream (file);; byte[] buffer=New byte[1024]; intN=0; while(N=in.read (buffer))!=-1) {out.write (buffer,0, N); } } finally { if(NULL!=Out ) {Out.close (); } if(NULL!=In ) {In.close (); } } }
Folder replication
Public Static voidCopydir (String OldPath, String NewPath)throwsIOException {File oldFile=NewFile (OldPath); File[] Listfiles=Oldfile.listfiles (); File NewFile=NewFile (NewPath); if(!newfile.exists ()) {Newfile.mkdir (); } for(File file:listfiles) {if(File.isdirectory ()) {copydir (File.getpath (), Newpath.concat (File.separator). Concat (File.getname ())); } if(File.isfile ()) {CopyFile (File.getpath (), Newpath.concat (File.separator). Concat (File.getname ())); } } }
Java file, folder replication