集册 Java实例教程 使用FileReader和FileWriter逐字符复制文件

使用FileReader和FileWriter逐字符复制文件

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

472
使用FileReader和FileWriter逐字符复制文件

import java.io.FileReader;

import java.io.FileWriter;
/* from 
时   代    Java - nowjava.com*/

import java.io.IOException;


public class CopyCharacters {

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


        FileReader inputStream = null;

        FileWriter outputStream = null;


        try {

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

            outputStream = new FileWriter("characteroutput.txt");


            int c;

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

                outputStream.write(c);
                /* 
                *来 自
                 N o  w  J a v a . c o m - 时  代  Java
                */

            }

        } finally {

            if (inputStream != null) {

                inputStream.close();

            }

            if (outputStream != null) {

                outputStream.close();

            }

        }

    }

}


展开阅读全文