【Java】字节流复制图片


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

public class CopyPngDemo {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("D:\\MyProject\\Java\\LearnJava1\\src\\Demo4\\img.png");
        FileOutputStream fos = new FileOutputStream("D:\\MyProject\\Java\\LearnJava1\\src\\Demo4\\img2.png");
        byte[] bys = new byte[1024];
        int len;
        while ((len = fis.read(bys)) != -1) {
            fos.write(bys);
        }
        fos.close();
        fis.close();
    }
}

 

posted @ 2022-04-19 20:38  木子欢儿  阅读(24)  评论(0编辑  收藏  举报