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

    字符缓冲流

    1.缓冲流:不具备读写数据的能力,可以提高读取数据的效率,扩展功能,内部维护字符数组                                                                    

                                                                              

     2.BufferedReader:缓冲输入字符流                                              

    1. 特殊功能:readLine()     读取一行数据                              

       1.创建通道并指定路径                                                    

        FIleReader reader = new FileReader(“D:\a.txt”);         

       2.创建缓冲流                                                            

        BufferedReader buffer = new BufferedReader(reader);     

       3.循环读取一行                                                          

        String string = null;                                                  

        while((string = buffer.readLine()) != null){                 

            System.out.println(string);                                        

    }                                                                      

       4.关闭流                                                                

        buffer.close();                                                    

                                                                               

    3.BufferedWrite:缓冲输出字符流                                            

    1.内部提供一个8192长度的字符数组作为缓冲区                           

    2.作用:                                                                  

          A)提高写入的效率                                                    

          B)提高FileWrite的功能                                              

     3. 特殊功能:newline();  数据换行显示                                  

      1.创建通道并指定路径                                                     

        FileWrite write = new FIleWrite(“D:\a.txt”);          

      2.建立缓冲流                                                             

        BuferedWrite buffer = new BufferedWrite(write);           

      3.数据换行显示                                                           

        buffer.newLine();                                       

      4.开始写入数据    //   也是系统换行                                  

        Buffer.write(“这是要写入的数据”);                                 

      5.关闭资源 (会自动调用flush())                                         

        bufferedWrite.close();

  • 相关阅读:
    初学者之 Git 和 Github
    80端口与8080端口是两种不同的端口吗?他们到底有什么区别和联系?
    redis 基础(一) 初步了解redis
    spring 基础(四)浏览器跨域访问+拦截器(Interceptor)
    mysql商业版和社区版
    spring 基础(五) spring mvc RESTful
    解决idea控制台打印乱码问题
    springBoot 基础-拓展(二) 记录一些常用的配置文件
    SpringBoot 基础(零) SpringBoot和Spring
    springBoot 基础-拓展(一) spring-boot-starter
  • 原文地址:https://www.cnblogs.com/z-jun/p/6179991.html
Copyright © 2011-2022 走看看