BufferedWriter的用法

/**
 * 通过BufferedWriter写入数据到a.txt的文件中
 * 
 * 
 * 输出流 , 字符流,处理流
 */
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;


public class Test {
public static void main(String[] args) {
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter("d://a.txt");
bw = new BufferedWriter(fw);
bw.write("你猜我猜不猜");
bw.newLine();
//下一行
bw.write("我不知道");
bw.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
}

你可能感兴趣的:(java)