zoukankan      html  css  js  c++  java
  • 字节缓冲流

    字节缓冲区                                                             

     1.Buffer开头的类:所有缓冲流都是以Buffer开头                             

                                                                               

    A)                                                                        

     1.BufferInputStream:缓冲输入字节流                                       

        目的:提高读取文件的效率                                               

     2.注意:BufferedInputStream 不具备读写数据的功能                          

     3.内部实现:里面维护一个了8kb的byte数组                                 

     4.BufferInputStream步骤:                                                 

        1.找到目标文件                                                         

         File file = new File(“C:\Users\cdlx2016\Desktop\a.txt”);        

        2.建立FileInputStream                                                  

         FileInputStream input = new FileInputStream(file);                    

        3.创建缓冲输入字节流,并且传入一个FileInputStream                      

         BufferedInputStream buffer = new BufferedInputStream(input);     

        4.读取数据                                                             

         int content = 0;                                                 

         while((content = buffer.read()) != -1){ //一个一个读取     

            System.out.print((char)content)                            

    }                                                                      

        5.关闭资源                                                             

         buffer.close();                                                       

                                                                               

    B)                                                                        

     1.BufferedOutputStream:缓冲字节输出流                                    

     2.作用:提高文件的输出的效率,可以提供其他方法                            

     3.使用步骤                                                                

        1.找目标                                                               

    File file = new File(“C:\Users\cdlx2016\Desktop\a.txt”)         

        2.建立FileOutputStream                                                 

         FileOutputStream output = new FileOutputStream(file);                 

        3.创建缓冲字节输出流                                                   

         BufferedOutputStream buffer = new BufferedOutputStream(file);   

        4.写数据(还不会写入磁盘中,如果数组数据存满,会自动写入磁盘)         

        int content = 0;                                                  

        while((content = buffer.read() != -1){                          

            bufferIn.write()    ;                                             

            5.数据写入磁盘:调用flush()刷新数据                                

                Buffer.flush();                                 

    }                                                                      

        6.关闭资源:默认调用flush()                                            

         buffer.close();     

  • 相关阅读:
    f.lux
    Gidot TypeSetter (排版助手) 3.1.1.2
    FastStone Image Viewer --- 图片查看器
    www.nocmd.com 精品软件 坚持绿色之路 共筑生态之基
    Geek Uninstaller 1.4.5.136 卸载工具绿色版
    在线统计,在线调查意见,在线报名 --- 麦客
    QQ群管理 --- 免费提取QQ群所有成员
    8个在线接收手机短信验证码的免费网络服务整理
    微信群成员导出工具2.3下载 & 歪碰微信成员导出工具
    安装VSTO环境的方法
  • 原文地址:https://www.cnblogs.com/z-jun/p/6171101.html
Copyright © 2011-2022 走看看