zoukankan      html  css  js  c++  java
  • IO流10 --- 缓冲流(字节型)实现非文本文件的复制 --- 技术搬运工(尚硅谷)

    • 字节型缓冲流,BufferedOutputStream默认缓冲区大小 8192字节byte,满了自动flush()
    @Test
    public void test6(){
        File srcFile = new File("FLAMING MOUNTAIN.JPG");
        File destFile = new File("FLAMING MOUNTAIN2.JPG");
        FileInputStream fis = null;
        FileOutputStream fos = null;
    
        try {
            //节点流
            fis = new FileInputStream(srcFile);
            fos = new FileOutputStream(destFile);
            //缓冲流
            BufferedInputStream bis = new BufferedInputStream(fis);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
    
            //复制文件
            byte[] buffer = new byte[10];
            int len;
            while ((len = bis.read(buffer)) != -1){
                bos.write(buffer, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //关闭外层流,内层自动关闭
            if (bos != null){
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (bis != null){
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    

      

  • 相关阅读:
    百度图片
    在线人数统计
    mysql简易导入excel
    asp.net 导出excel带图片
    C# 正则验证
    js生成随机数
    YQL获取天气
    取html里的img和去html标签
    客户端信息获得《转》
    使用ASP.NET上传图片汇总
  • 原文地址:https://www.cnblogs.com/noyouth/p/11699339.html
Copyright © 2011-2022 走看看