- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- public class testBufferFileCopy {
- public static void main(String[] args) {
- FileReader fr = null;
- FileWriter fw = null;
-
- try{
- fr = new FileReader("D:\\test.java");
- fw = new FileWriter("c:\\test.java");
- }catch(IOException e){
- e.printStackTrace();
- }
- BufferedReader bfr = new BufferedReader(fr);
- BufferedWriter bfw = new BufferedWriter(fw);
-
- try{
- String temp = null;
- while((temp = bfr.readLine())!=null)
- bfw.write(temp);
- bfw.newLine();//这一行完全没有作用啊!
- bfw.flush();
- }catch(IOException e){
- e.printStackTrace();
- }finally{
- try {
- if(bfr!=null)
- bfr.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try{
- if(bfw!=null)
- bfw.close();
- } catch(IOException e){
- e.printStackTrace();
- }
- }
- }
- }
复制代码 程序结果为
为什么newLine()并没有加入一个换行符?
|
|