• 关于缓冲流


    package com.bjsxt.ios3;
    
    import java.io.*;
    
    /**
     *1.只要关闭高层流即可,底层流不用手动关闭;因为高层的关闭方法就是把底层流关闭
     *
     *2.何时将输出缓冲区的内容写入硬盘
     *   1.输出缓冲区满,自动写入硬盘(刷新 flush)
     *   2.close()会先刷新
     *   3.手动的flush()
     * 3.缓冲流的原理
     */
    public class TestBuffredStream2 {
        public static void main(String[] args) throws IOException {
            //1.创建流
    //        InputStream fis = new FileInputStream("e:/JDK_API_1_6_zh_CN.CHM");
    //        OutputStream fos = new FileOutputStream("e:\\JDK_API_1_6_zh_CN2.CHM");
    //        BufferedInputStream bis = new BufferedInputStream(fis);//8192
    //        BufferedOutputStream bos = new BufferedOutputStream(fos);//8192
            BufferedInputStream bis =
                    new BufferedInputStream(new FileInputStream("e:/JDK_API_1_6_zh_CN.CHM"));//8192
            BufferedOutputStream bos =
                    new BufferedOutputStream(new FileOutputStream("e:\\JDK_API_1_6_zh_CN2.CHM"));//8192
            //2.使用流
            //2.1 准备一个中转站(一个字节)
            byte [] buf = new byte[1024];
            //先读一个字节
            int len= bis.read(buf);//读源文件的一个字节赋给n
            while(len  != -1){ //读到 了数据,还没有到文件末尾
                //写一个字节
                bos.write(buf,0,len);
                //再读一个字节
                len= bis.read(buf);//读源文件的一个字节赋给n
            }
    
            //3.关闭流
            bos.flush();
            bis.close();
            bos.close();
    //        fis.close();
    //        fos.close();
        }
    }
  • 相关阅读:
    flask路由+视图
    flask基本使用1
    返回对象时字典化
    python3连接redis
    selected_related和prefetch_related
    django删除migrations导致初始化数据库失效
    vue添加拦截器(身份认证)以及cookie认证
    vue添加使用全局变量
    列表:动手试一试
    转来的字符串编辑方式
  • 原文地址:https://www.cnblogs.com/vincentmax/p/14245145.html
Copyright © 2020-2023  润新知