BufferedWriter基本用法 BufferedReader基本用法 字符缓冲流复制文本文件 特殊功能 BufferedWriter void newLine() BufferedReader String readLine() 字符缓冲流特殊功能复制文本文件
BufferedReader
private static void read() throws IOException {
// 创建字符缓冲输入流对象
BufferedReader br =
new BufferedReader(new FileReader("bw2.txt"));
// public String readLine():一次读取一行数据
// String line = br.readLine();
// System.out.println(line);
// line = br.readLine();
// System.out.println(line);
// 最终版代码
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
//释放资源
br.close();
}
BufferedWriter
private static void write() throws IOException {
// 创建字符缓冲输出流对象
BufferedWriter bw =
new BufferedWriter(new FileWriter("bw2.txt"));
for (int x = 0; x < 10; x++) {
bw.write("hello" + x);
// bw.write("\r\n");
bw.newLine();
bw.flush();
}
bw.close();
}