第四次作业

本次作业实现了文件的拷贝,通过修改一次读取写入字节实现了快速拷贝。
package copy;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class copy {
/**

  • @param args
    */

public static void main(String[] args) {

long startTime = System.currentTimeMillis();//获取当前时间
try {
    FileInputStream fis = new FileInputStream ("a.mp3");
    FileOutputStream fos = new FileOutputStream ("temp.mp3");
    int read = fis.read();
     byte[] b = new byte[1024*100]; 
     int len; 
     while ( (len = fis.read(b)) != -1) { 
     fos.write(b, 0, len); 
     }

// while ( read != -1 ) {
// fos.write(read);
// read = fis.read();
// }
fis.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();

原文地址:https://www.cnblogs.com/yinxinlei/p/5375045.html