JavaSE 高级 第17节 写入缓冲类BufferedWriter
2016-07-24
1,BufferedWriter
debug:
F5 进入方法
F6 执行下一行代码
F7 退出方法
F8 跳到下一个断点
package com.java1995; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class CopyFile { public static void main(String[] args) { // 导入包的快捷键Ctrl+Shift+O FileReader fr = null; FileWriter fw = null; BufferedReader br = null; BufferedWriter bw = null; try { fr = new FileReader("C:\\java1995\\workspace_se_2\\day17\\src\\com\\java1995\\CopyFile.java"); fw = new FileWriter("C:\\java1995\\workspace_se_2\\day17\\src\\out.txt"); br = new BufferedReader(fr); bw = new BufferedWriter(fw); int c = 0; while ((c = br.read()) != -1) { bw.write(c); // bw.flush(); } bw.flush(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { fr.close(); fw.close(); br.close(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
【参考资料】