文件的复制通过字符流和缓冲流(Buffered)
public class FileReaderAndWriter {
public static void main(String[] args) {
try {
FileReader fr = new FileReader("learn.txt");
FileWriter fw = new FileWriter("learn3.txt");
BufferedReader bf = new BufferedReader(fr);
BufferedWriter bw = new BufferedWriter(fw);
String text;
while ((text = bf.readLine()) != null) {
bw.write(text+"\n");
}
bw.flush();
bw.close();
bf.close();
fw.close();
fr.close();
System.out.println("done");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
本文标题:文件的复制通过字符流和缓冲流(Buffered)
本文链接:https://www.haomeiwen.com/subject/zildjftx.html
网友评论