本帖最后由 地狱天堂 于 2014-8-10 21:07 编辑
为什么bufw.flush(); 加不加效果一样?
- <p>import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;</p><p>public class CopyTestByBuf {
- /*
- * 通过缓冲区复制一个.java文件。
- *
- *
- */
- public static void main(String[] args) {
- BufferedReader bufr = null;
- BufferedWriter bufw = null;
- String lin = null;
- try {
- bufr = new BufferedReader(new FileReader("c:/test44.java"));
- bufw = new BufferedWriter(new FileWriter("d:/demo.java"));
- while ((lin = bufr.readLine()) != null) {
- bufw.write(lin);
- bufw.newLine();
- // bufw.flush(); //这里flush();加不加结果都一样,可以完成复制。为什么?
- }
- } catch (IOException e) {
- System.out.println(e.toString());
- } finally {
- try {
- if (bufw != null)
- bufw.close();
- } catch (IOException e) {
- System.out.println(e.toString());
- } try {
- if (bufr != null)
- bufr.close();
- } catch (IOException e) {
- System.out.println(e.toString());
- }
- }
- }
- }
复制代码
|
|