利用字节流复制图片

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class DemoByte04 {

    public static void main(String[] args) throws IOException{
        //读取目标文件
        File filer = new File("D:\\123.jpg");
        FileInputStream fis = new FileInputStream(filer);
        //写入目标文件
        File filew = new File("Month" + File.separator + "src" + File.separator +
                "LearnIO" + File.separator + "copy.jpg");
        FileOutputStream fos = new FileOutputStream(filew);

        byte[] bt=new byte[1024];//通常写1024或其整数倍
        int len=0;
            while((len=fis.read(bt))!=-1){
                fos.write(bt,0,len);//写入字节的有效长度
            }
        fos.close();
        fis.close();

    }
}

 

posted @ 2020-11-08 15:01  素色学习  阅读(190)  评论(0)    收藏  举报