废话不多说 , : :
package com.edu.xynu; Importer java.io.BufferedInputStream; Importer java.io.BufferedOutputStream; Importer java.io.file; import java.io.fileInputStream; Importer java.io.fileOutputStream; Importer java.io.ioException; classe publique IounitCopy {// 按字节 public static void copybyte (fichier srcfile, file destfile) lève ioException {fileInputStream fis = new FileInputStream (srcfile); FileOutputStream fos = new FileOutputStream (destFile); int i; while ((i = fis.read ())! = - 1) {fos.write (i); } fis.close (); fos.close (); } // 按字节数组 public static void copyByTearray (fichier srcfile, file destfile) lève ioException {fileInputStream fis = new FileInputStream (srcfile); FileOutputStream fos = new FileOutputStream (destFile); octet [] buf = nouveau octet [10 * 1024]; int i; while ((i = fis.read (buf, 0, buf.length))! = - 1) {fos.write (buf, 0, i); } fis.close (); fos.close (); } // 字节缓冲流 public static void copyBuff (fichier srcfile, file destfile) lève ioException {bufferedInputStream bis = new BufferedInputStream (new FileInputStream (srcfile)); BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream (destFile)); int i; while ((i = bis.read ())! = - 1) {bos.write (i); } bos.flush (); bis.close (); bos.close (); } // 字节数组批量读取 缓冲输出流写入 public static void copyBuffArray (fichier srcfile, file destfile) lève ioException {fileInputStream bis = new FileInputStream (srcfile); BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream (destFile)); octet [] buf = nouveau octet [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; Importer java.io.file; Importer java.io.ioException; classe publique IounitsCopyTest {public static void main (String [] args) {// TODO Méthode générée automatique Stub try {long start = System.currenttimemillis (); // iounitcopy.copybyte (nouveau fichier ("c: //1.mp3"), nouveau fichier (// "c: //2.mp3")); // 90713ms // iounitcopy.copybytearray (nouveau fichier ("c: //1.mp3"), nouveau fichier (// "c: //3.mp3"); // 41ms // IounitCopy.copyByBuff (nouveau fichier ("c: //1.mp3"), nouveau fichier (// "c: //4.mp3")); // 556ms // iounitcopy.copybybytearray (nouveau fichier ("c: //1.mp3"), nouveau fichier (// "c: //5.mp3")); // 30ms find = Systems. System.out.println (End-Start); } catch (ioException e) {// TODO Bloc de capture généré automatiquement e.printStackTrace (); }}}测试文件是