s-day09--字符缓冲流中特有的功能

This commit is contained in:
xx
2026-10-23 16:20:44 +08:00
parent 84eda24f96
commit 1220e4cb1a
@@ -0,0 +1,44 @@
package com.inmind.buffered01;
import java.io.*;
/*
6.字符缓冲流中特有的功能
BufferedWriter: newLine 它能够进行多个系统之间的换行的兼容
BufferedReader: readLine 它能够将文件中的内容按一行文本来读取
String readLine() 读一行文字。
*/
public class BufferedDemo04 {
public static void main(String[] args) throws Exception {
//使用字符缓冲输入流,一次读取一行内容
BufferedReader br = new BufferedReader(new FileReader("target3.txt"));
/*String line = br.readLine();
System.out.println(line);
line = br.readLine();
System.out.println(line);*/
String line;//用来保存读取到的一行内容
while ((line = br.readLine())!=null) {
System.out.println(line);
}
br.close();
}
public static void method(String[] args) throws Exception {
//使用字符缓冲输出流,输出3行内容
BufferedWriter bw = new BufferedWriter(new FileWriter("target3.txt"));
bw.write("我是谁");
bw.flush();
bw.newLine();//换行
bw.write("我在哪");
bw.flush();
bw.newLine();
bw.write("我在干嘛");
bw.flush();
bw.newLine();
bw.close();
}
}