java第四次作业

package lianxi;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

复制代码
public class CopyFile {
public static void copy(File a,File b){
    try {
        FileInputStream fis = new FileInputStream("a.mp3");
        FileOutputStream fos = new FileOutputStream("temp.mp3");
        byte[] buf = new byte[1024];
        int len;
        int read = fis.read();
        while((len = fis.read(buf))!=-1){
            fos.write(buf, 0, len);
        }
        fis.close();
        fos.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
public static void main(String[] args) {
    // TODO Auto-generated method stub
    File a = new File("");
    File b = new File("");
    long start,end;
    start = System.currentTimeMillis();
    copy(a,b);
    end = System.currentTimeMillis();
    System.out.println("复制所用时间:" + (end - start) + "ms");
}
}
复制代码
posted @ 2016-04-17 18:01  半岛弱弱  阅读(155)  评论(0编辑  收藏  举报