Nonsense is not much said, the key code as described below:
Package com.edu.xynu;
Import Java.io.BufferedInputStream;
Import Java.io.BufferedOutputStream;
Import Java.io.File;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import java.io.IOException; public class Iounitcopy {//per byte public static void Copybybyte (File srcfile,file destfile) throws ioexception{FileInput
Stream fis=new FileInputStream (srcfile);
FileOutputStream fos=new FileOutputStream (destfile);
int i;
while ((I=fis.read ())!=-1) {fos.write (i);
} fis.close ();
Fos.close (); }//By byte array public static void Copybybytearray (File srcfile,file destfile) throws ioexception{FileInputStream fis=new Fi
Leinputstream (Srcfile);
FileOutputStream fos=new FileOutputStream (destfile);
byte []buf=new byte[10*1024];
int i;
while ((I=fis.read (buf, 0, buf.length))!=-1) {fos.write (buf, 0, I);
} fis.close ();
Fos.close (); }//Byte buffered stream public static void Copybybuff (File srcfile,file destfile) throws ioexception{Bufferedinputstream bis=new Buf Feredinputstream (NewFileInputStream (srcfile));
Bufferedoutputstream bos=new Bufferedoutputstream (New FileOutputStream (DestFile));
int i;
while ((I=bis.read ())!=-1) {bos.write (i);
} bos.flush ();
Bis.close ();
Bos.close (); }//byte array bulk read buffered output stream write to public static void Copybybuffarray (File srcfile,file destfile) throws ioexception{FileInputStream
Bis=new FileInputStream (srcfile);
Bufferedoutputstream bos=new Bufferedoutputstream (New FileOutputStream (DestFile));
byte [] buf=new byte[10*1024];
int Len;
while ((Len=bis.read (buf,0,buf.length))!=-1) {bos.write (Buf,0,len);
} bos.flush ();
Bis.close ();
Bos.close ();
}} package Com.edu.xynu;
Import Java.io.File;
Import java.io.IOException; public class Iounitscopytest {public static void main (string[] args) {//TODO auto-generated method stub try {long
Start=system.currenttimemillis (); Iounitcopy.copybybyte (New file ("C:\\1.mp3"), new file (//"C:\\2.mp3"));//90713ms//Iounitcopy.copybybytearray (new File ("C:\\1.mp3"), new file (///"C:\\3.mp3 "));//41ms//Iounitcopy.copybybuff (New file (" C:\\1.mp3 "), new file (//" C:\\4.mp3 "));//556ms//Iounitcopy.copy
Bybytearray (New file ("C:\\1.mp3"), new file (//"C:\\5.mp3"));//30ms long End=system.currenttimemillis ();
System.out.println (End-start);
catch (IOException e) {//TODO auto-generated catch block E.printstacktrace (); }
}
}
The test file is