IO流入门-第三章-FileInputStream_FileOutputStream复制

利用FileInputStream和FileOutputStreamj进行复制粘贴

/*
    文件复制粘贴
*/

import java.io.*;
public class FileInput_OutputStreamCopy
{
    public static void main(String[] args) throws Exception
    {
        
        //创建输入流
        FileInputStream fis = new FileInputStream("FileInput_OutputStreamCopy.java");

        //创建输出流
        FileOutputStream fos = new FileOutputStream("D:\\FileInput_OutputStreamCopy.java");

        int temp = 0;
        byte[] bytes = new byte[1024];

        while((temp = fis.read(bytes)) != -1){
            //将byte数组中内容直接写入
            fos.write(bytes,0,temp);
        }

        fos.flush();

        fis.close();        
        fos.close();
    }
}

 

posted @ 2017-04-13 15:56  bookwed  阅读(221)  评论(0编辑  收藏  举报