博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
字符缓冲流
阅读量:4935 次
发布时间:2019-06-11

本文共 740 字,大约阅读时间需要 2 分钟。

字符缓冲流

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.开始写入数据    //   \r\n也是系统换行                                  

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

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

    bufferedWrite.close();

转载于:https://www.cnblogs.com/z-jun/p/6179991.html

你可能感兴趣的文章