Use BufferedReader and BufferedWriter to copy text file - Java File Path IO

Java examples for File Path IO:BufferedReader

Description

Use BufferedReader and BufferedWriter to copy text file

Demo Code


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class BufferedReaderTest {

    public static void main(String[] args) throws IOException {
        System.out.println(System.getProperty("file.encoding"));
        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;
        try {//from   w ww .j  av a  2 s . c o m
            bufferedReader = new BufferedReader(new FileReader("C:/input.txt"));
            bufferedWriter = new BufferedWriter(new FileWriter("C:/output.txt"));
            String data;
            while ((data = bufferedReader.readLine()) != null) {
                bufferedWriter.append(new String(data));
                System.out.println(data);
            }
        } finally {
            bufferedWriter.close();
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        }
    }

}

Related Tutorials