zoukankan      html  css  js  c++  java
  • 作业四

    一、源程序
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;

    public class CopyFile {

    /**
     * @param args
     */
    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[2048];
    		int length;
    		int read = fis.read();
    		while((length = fis.read(buf))!=-1){
    			fos.write(buf, 0, length);
    		}
    		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");
    }
    

    }

    二、改进方法代码:
    byte[] buf = new byte[2048];
    int length;
    int read = fis.read();
    while((length = fis.read(buf))!=-1){
    fos.write(buf, 0, length);
    }
    三、测试时间代码:
    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");
    四、测试结果

  • 相关阅读:
    Linux开机自动启动ORACLE设置
    linux下查找过滤文件内容
    weblogic 修改控制台访问路径
    ASM实例挂载磁盘失败错误日志
    weblogic服务器下一个domain建多个server(端口)
    Oracle Profile
    codeforces_724C_Ray Tracing
    struts2_validate表单验证
    struts2.5.2 通配符问题_亲测有用
    hibernate+struts2
  • 原文地址:https://www.cnblogs.com/humeiling/p/5365542.html
Copyright © 2011-2022 走看看