PackageCom.lanxi.demo2_6;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.OutputStream;/*** Copy a picture from one directory to another (PS: copy is not mobile) *@authorAdministrator * 1) Create a picture file at the destination address 2) read the byte stream of the source address file 3) write the read byte stream to the destination address of the file 4) flush the output stream and Shut it down.*/ Public classTest { Public Static voidMain (string[] args) {//1.1 Creating a picture storage pathFile filefrom=NewFile ("D:/c/c1/picture.jpg"); //1.2 Create a path after the picture is movedFile fileto=NewFile ("D:/c/c2/picture.jpg"); InputStream input=NULL; OutputStream Output=NULL; Try { //use the original picture file path as the input streaminput=NewFileInputStream (Filefrom); //move the post image path as the output streamoutput=NewFileOutputStream (FileTo); byte[] by=New byte[1024]; //traversal Read and write Try { while(Input.read ()!=-1) {output.write (by); } output.flush (); } Catch(IOException e) {e.printstacktrace (); } } Catch(FileNotFoundException e) {e.printstacktrace (); }finally{ Try { //Close the streamInput.close (); Output.close (); } Catch(IOException e) {e.printstacktrace (); } System.out.println ("Copy success!!" "); } }}
Copy a picture from one directory to another (PS: copy is not mobile)