package com.sf._05_缓冲流;

import java.io.*;

public class Test {
    /**
     * 拷贝d: 1.avi 文件
     * 分别一次读取1 个字节
     * 一次读取1024个字节
     * 使用缓冲流去读取
     * 看耗时时间
     * @param args
     */
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(new File("D:\\1.mp4"));

        FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\3.mp4"));
        //创建字节缓冲流
        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
        // 一次行读取一个字节
        long startTime = System.currentTimeMillis();
        int len = -1;
        byte[] buffer = new byte[1024];
        while ((len = bufferedInputStream.read(buffer))!=-1){
            // 读完直接写出去
            bufferedOutputStream.write(buffer,0,len);
        }
        long endTime = System.currentTimeMillis();
        System.out.println((endTime-startTime) +"毫秒");
        // 关闭资源
        fileInputStream.close();
        fileOutputStream.close();
    }
}
