集册 Java实例教程 使用FileInputStream和FileOutputStream逐字节复制文件

使用FileInputStream和FileOutputStream逐字节复制文件

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

416
使用FileInputStream和FileOutputStream逐字节复制文件

import java.io.FileInputStream;/* 来自 nowjava.com - 时代Java*/

import java.io.FileOutputStream;

import java.io.IOException;


public class CopyBytes {

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


        FileInputStream in = null;

        FileOutputStream out = null;


        try {

            in = new FileInputStream("xanadu.txt");

            out = new FileOutputStream("outagain.txt");

            int c;
/** N o w J a v a . c o m - 时代Java 提 供 **/

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

                out.write(c);

            }

        } finally {

            if (in != null) {

                in.close();

            }

            if (out != null) {

                out.close();

            }

        }

    }

}


展开阅读全文