Bootstrap

Buffered字节处理流拷贝文件

Buffered字节处理流拷贝文件

8891b17079554270ac65e2f33121216d.png

public class BufferedCopy02 {
    public static void main(String[] args) {
        String srcFilePath = "D:\\Chou.jpg";
        String destFilePath = "D:\\Chou2.jpg";

        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        byte[] buff = new byte[1024];
        int readLen = 0;
        try {
            bis = new BufferedInputStream(new FileInputStream(srcFilePath));
            bos = new BufferedOutputStream(new FileOutputStream(destFilePath));
            while ((readLen = bis.read(buff)) != -1){
                bos.write(buff,0,readLen);
            }
            System.out.println("拷贝成功!");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (bis != null){
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (bos != null){
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}

f602bf1030304e99a3c732d1b63a29a0.png

aa0be8920e2048dfb322fd016b9184f9.png

 

 

;