集册 Java实例教程 带BufferedReader和BufferedWriter的缓冲副本

带BufferedReader和BufferedWriter的缓冲副本

欢马劈雪     最近更新时间:2020-01-02 10:19:05

476
使用BufferedReader和BufferedWriter的缓冲副本
//from n o w j a   v  a . c o m - 时  代  Java

import java.io.FileReader;

import java.io.FileWriter;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.IOException;


public class BufferedCopy {

    public static void main(String[] args) throws IOException {

        BufferedReader inputStream = null;

        BufferedWriter outputStream = null;


        try {

            inputStream = new BufferedReader(new FileReader("xanadu.txt"));

            outputStream = new BufferedWriter(new FileWriter(

                    "characteroutput.txt"));/**from N o w J a v a . c o m**/


            int c;

            while ((c = inputStream.read()) != -1) {

                outputStream.write(c);

            }

        } finally {

            if (inputStream != null) {

                inputStream.close();

            }

            if (outputStream != null) {

                outputStream.close();

            }

        }

    }

}


展开阅读全文