package xxx.yyy.zzz;
import java.io.*;
public class FrAndFwDemo {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("D:\\java\\java_io_file\\demo\\desFile.txt");
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter("D:\\java\\java_io_file\\demo\\desFile-1.txt");
BufferedWriter bw = new BufferedWriter(fw);
String line;
while ((line = br.readLine()) != null){
System.out.println(line);
bw.write(line); //换行操作
bw.newLine();
bw.flush();
}
/*
char[] buffer = new char[8*1024];
int c;
while ((c = fr.read(buffer, 0, buffer.length)) != -1){
String s = new String(buffer, 0, c);
System.out.println(s);
fw.write(buffer, 0, c);
fw.flush();
}
*/
fw.close();
br.close();
fr.close();
}
}
Java基础一:字符流过滤器(BufferedReader和BufferedWriter )
最新推荐文章于 2021-03-10 22:20:39 发布