Copy a picture from one directory to another (PS: copy is not mobile)

Source: Internet
Author: User

 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)

Related Article

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.