import java.io.*;
//字符缓冲流
// 特有功能:换行/读一行文字
public class Demo05 {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter("idea_demo\\copy5.java"));
for (int i = 0; i < 10; i++) {
bw.write("hello");
bw.newLine(); //行分隔符
}
bw.close();
BufferedReader br =new BufferedReader(new FileReader("idea_demo\\copy5.java"));
/*int len;
char[] chs = new char[1024];
while ((len = br.read(chs)) != -1) {
System.out.print(new String(chs, 0, len));
}
br.close();*/
String line;
while ((line = br.readLine())!=null){ //读一行文字
System.out.println(line);
}
}
}
字符缓冲流的特有功能之换行操作
最新推荐文章于 2022-10-11 11:48:48 发布