字符缓冲区输入输出流

文件输入输出流既然有缓冲区,那么字符也就会有。他们的一些用法基本是一致的:

字符缓冲区输出流:

 1 package com.hw.file0222;
 2 
 3 import java.io.BufferedWriter;
 4 import java.io.FileWriter;
 5 import java.io.IOException;
 6 
 7 import org.junit.Test;
 8 
 9 public class DemoBufferedFileWriter {
10     
11     @Test
12     public void testBufferedFileWriter(){
13         BufferedWriter writer = null;
14         try {
15             
16             writer = new BufferedWriter(new FileWriter("F://骚操作//demotest02.txt"));
17             writer.write('中');
18             writer.write('国');
19             writer.write('很');
20             writer.write('强');
21             writer.write('大');
22             writer.write(' ');
23             writer.write("我们很自豪");
24         } catch (IOException e) {
25             // TODO Auto-generated catch block
26             e.printStackTrace();
27         }finally{
28             try {
29                 if(writer != null){
30                     writer.close();
31                 }
32             } catch (IOException e) {
33                 // TODO Auto-generated catch block
34                 e.printStackTrace();
35             }
36         }
37         
38     }
39 }

字符缓冲区输入输出流


 

 字符缓冲区输入流:

 

上一篇:python爬虫之xpath解析


下一篇:速记IO流中常用的几种流