Packageflow;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.OutputStream; Public classStream {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubDeldir ("D://mydrivers"); } Public Static voidcopyFile (String src,string dest) {Try{InputStream InputStream=NewFileInputStream (SRC); OutputStream OutputStream=NewFileOutputStream (dest); File File=NewFile (dest); if(!file.exists ())Try{file.createnewfile (); } Catch(IOException E1) {//TODO auto-generated Catch blockE1.printstacktrace (); } intch; Try { while((Ch=inputstream.read ())!=-1) {outputstream.write (CH); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } Public Static voidrenamefile (String path,string oldname,string newname) {if(!oldname.equals (newname)) {File OldFile=NewFile (path+ "/" +oldname); File NewFile=NewFile (path+ "/" +newname); if(Newfile.exists ()) {System.out.println ("The file already exists"); } Else{Oldfile.renameto (newFile); } } } Public Static voidDeldir (String path) {File dir=NewFile (path); if(Dir.exists ()) {file[] tmp=Dir.listfiles (); for(inti=0; i<tmp.length; i++) { if(Tmp[i].isdirectory ()) {Deldir (path+"/"+tmp[i].getname ()); } Else{tmp[i].delete (); }}} dir.delete (); }}
Java stream Copy, rename, delete directory