Java file input and output-bmp picture copy

import java.io.*;

public class Dump {
    public static void main(String[]args) {
        try
        {
            dump( new FileInputStream("aaa.bmp"),   
                  new FileOutputStream("bbb.bmp"));
        }//文件输入aaa.bmp,文件输出bbb.bmp(文件复制)
        catch(FileNotFoundException fex)
        {
            fex.printStackTrace();
        }
        catch (IOException ioe)
        {
            ioe.printStackTrace();
        }
    }

    public static void dump(InputStream src, OutputStream dest)
    throws IOException//抛出可能的IO异常
    {
        InputStream input = new BufferedInputStream(src);
        OutputStream output = new BufferedOutputStream(dest);
		//处理复制过程,先通过一个缓冲区
        byte[] data = new byte[1024];   //字节数组,1024个字节
        int length = -1;
        while ((length = input.read(data)) != -1) {
            output.write(data, 0, length);//写出,data缓冲区里面从第0个开始,length长
        }
        input.close();
        output.close();
    }
}

Insert picture description here
Insert picture description here

Published 28 original articles · won praise 2 · Views 3259

Guess you like

Origin blog.csdn.net/Maestro_T/article/details/89739024