使用流复制图片

package cn.xs.Day05;
/**
 * 图片的复制
 */

import java.io.*;

public class ioCopy {
    public static void main(String[] args) throws Exception {
        DataInputStream dis = new DataInputStream(new FileInputStream("E://2.jpg"));//获取图片文件的位置
        DataOutputStream dos = new DataOutputStream(new FileOutputStream("E://4.jpg"));//复制图片所在的位置
        byte[] bytes = new byte[1024];//一次读取多少内容:1024个字节
        int temp;
        while ((temp=dis.read(bytes))!=-1){//从文件中读取字节
            dos.write(bytes,0,temp);//写给复制图片
        }
        dos.flush();
        dos.close();
        dis.close();
    }
}

猜你喜欢

转载自blog.csdn.net/gadxiong/article/details/80312168
今日推荐