It takes time to compare d:\\ application software \\vm.exe to C:\\vm.exe four methods 4>2>3>1
PackageCopy;ImportJava.io.BufferedInputStream;ImportJava.io.BufferedOutputStream;ImportJava.io.File;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;Importjava.io.IOException;/** File copy method, byte stream, one 4 way * 1. Byte stream reads and writes single bytes * 2. Byte stream reads and writes an array of bytes * 3. Byte buffers Read and write a single byte * 4. Byte buffers read and write byte arrays*/ Public classCopy { Public Static voidMain (string[] args)throwsIOException {Longs=System.currenttimemillis (); Copy_4 (NewFile ("e:\\ application software \\vm.exe"),NewFile ("C:\\vm.exe")); LongE=System.currenttimemillis (); System.out.println (e-s); } /** Method: Implement file Copy * 4. Byte stream read and write bytes array*/ Public Static voidCopy_4 (File src,file desc)throwsioexception{Bufferedinputstream bis=NewBufferedinputstream (NewFileInputStream (SRC)); Bufferedoutputstream Bos=NewBufferedoutputstream (NewFileOutputStream (DESC)); intLen=0; byte[] bytes=New byte[1024]; while((Len=bis.read (bytes))!=-1) {bos.write (bytes,0, Len); } bos.close (); Bis.close (); } /** Method: Implement file Copy * 3, byte stream buffer streams read/write single bytes*/ Public Static voidCopy_3 (File src,file desc)throwsioexception{Bufferedinputstream bis=NewBufferedinputstream (NewFileInputStream (SRC)); Bufferedoutputstream Bos=NewBufferedoutputstream (NewFileOutputStream (DESC)); intLen=0; while((Len=bis.read ())!=-1) {bos.write (len); } bos.close (); Bis.close (); } /** Method: Implement Replication * 2. Byte stream reading and writing bytes Array*/ Public Static voidCopy_2 (File src,file desc)throwsioexception{FileInputStream fis=NewFileInputStream (SRC); FileOutputStream Fos=NewFileOutputStream (DESC); intLen=0; byte[] bytes=New byte[1024]; while((Len=fis.read (bytes))!=-1) {fos.write (bytes,0, Len); } fos.close (); Fis.close (); } /** Method: Implement file Copy * 1. Byte stream read and write single bytes*/ Public Static voidCopy_1 (File src,file desc)throwsioexception{FileInputStream fis=NewFileInputStream (SRC); FileOutputStream Fos=NewFileOutputStream (DESC); intLen=0; while((Len=fis.read ())!=-1) {fos.write (len); } fos.close (); Fis.close (); }}
Java four ways to achieve copy comparison of character stream files