zoukankan      html  css  js  c++  java
  • Java缓冲流高效大文件的复制实例

    public class BufferedDemo {
    public static void main(String[] args) throws FileNotFoundException {
    // 记录开始时间
    long start = System.currentTimeMillis();
    // 创建流对象
    try (
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream("jdk8.exe"));
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("copy.exe"));
    ){
    // 读写数据
    int len;
    byte[] bytes = new byte[8*1024];
    while ((len = bis.read(bytes)) != -1) {
    bos.write(bytes, 0 , len);
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    // 记录结束时间
    long end = System.currentTimeMillis();
    System.out.println("缓冲流使用数组复制时间:"+(end - start)+" 毫秒");
    }
    }
    // 缓冲流使用数组复制时间:666 毫秒

     

    忘了他,我撸代码养你
  • 相关阅读:
    Python成长笔记
    Python成长笔记
    Python成长笔记
    Python成长笔记
    Python成长笔记
    Python成长笔记
    Python成长笔记
    Python成长笔记
    Python成长笔记
    解决Jenkins生成测试报告的问题
  • 原文地址:https://www.cnblogs.com/theworld/p/11650095.html
Copyright © 2011-2022 走看看