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!");
}
}
}
}
}
4399




被折叠的 条评论
为什么被折叠?



