Import Java.io.file;import Java.io.fileinputstream;import java.io.filenotfoundexception;import Java.io.fileoutputstream;import java.io.IOException; Public classDemo7 {/** * @param args * @throws ioexception*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubPopyimage (); } Public Static voidPopyimage () {LongTime1 =System.currenttimemillis (); //Find PathFile File =NewFile ("c:\\users\\zhangheng\\desktop\\d9cf11161c4ed2ad.jpg"); //Input Flow channelFileInputStream FileInputStream =NULL; Try{FileInputStream=Newfileinputstream (file); } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); }//buffers byte[] by =New byte[1024x768];//reading Data intCount =0; //the path to the pictureFile file1 =NewFile ("c:\\users\\zhangheng\\desktop\\dd.jpg"); //Output Flow channelFileOutputStream FileOutputStream =NULL; Try{FileOutputStream=NewFileOutputStream (FILE1); } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } //reading Data Try { while(Count = Fileinputstream.read (by))!=-1){ //System.out.println (New String (By,0,count)); //Write DataFileoutputstream.write (by); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } //Backward First off Try{fileoutputstream.close (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }//advanced back-off Try{fileinputstream.close (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } LongTime2 =System.currenttimemillis (); System. out. println (time2-time1)); }}
Byte output stream and input stream copy Picture