使用BufferedReader和BufferedWriter两个对象复制文件

import java.io.*;

public class TestBufferedReader{

    public static void main(String[] args){
        
        try{
            BufferedReader br = new BufferedReader(new FileReader("D:/Java/TestBufferedReader/TestBufferedReader.java"));
            BufferedWriter bw = new BufferedWriter(new FileWriter("D:/Java/TestBufferedReader/copy.txt"));
            String str = null;
            
            while((str = br.readLine()) != null){
                bw.write(str);
                bw.newLine();
            }
            bw.flush();
            bw.close();
            br.close();
        } catch(IOException e){
            e.printStackTrace();
        } 
    }

}

 

上一篇:io的转换流和缓冲流


下一篇:用户输入信息并存储