import java.io.*;
/*
對java IO BufferedWriter 使用的演示
*/
class BufferedDemo{
static BufferedWriter bw;
static FileWriter fw;
public static void main(String[] args){
try{
fw = new FileWriter("g:/bufferData.txt");
bw = new BufferedWriter(fw);
for(int i =0; i<5; i++){
bw.write("abcd");
//插入兼容換行符
bw.newLine();
//用到緩衝區就要刷新
bw.flush();
}
//關閉緩衝區,就是關閉緩衝區中的IO流對象
bw.close();
}
catch(IOException e){
System.out.println(e.toString() ) ;
}
finally{
if(bw != null){
try{
bw.close();
}catch(IOException e){
System.out.println(e.toString() ) ;
System.out.println("Can not close the Stream!");
}
}
}
}
}