Io流之实现文件的复制

package Io流;

import org.junit.Test;

import java.io.*;

/**
 * 实现文件的复制
 */
public class Demo04 {
    @Test
    public void test(){
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            File file = new File("d:\\11.txt");
            //输入流
            fis = new FileInputStream(file);
            //输出流
            fos = new FileOutputStream("e:\\11.txt",true);
            int ch = 0;
            while ((ch = fis.read())!= -1){
                fos.write(ch);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
posted @ 2021-01-24 18:19  dgxacc  阅读(85)  评论(0)    收藏  举报