##复制图片IO流的原理

复制图片IO流的原理

##分析:一个图片,我们是不是要先去读,读的话是不是要用输入流,读出来之后在写到我们的内存上,写就要用到输出流,这样我们才能看到

public class Demo03Copy {
    public static void main(String[] args) throws IOException{
        long s = System.currentTimeMillis();
        //1  创建输入流对象   读的数据源
        FileInputStream fis  = new FileInputStream("d:\kgc.jpg");
        //2   创建输出流对象  写入的目的
        FileOutputStream fos = new FileOutputStream("D:\my_java\kgc.jpg");
        //3  使用字节输入流中  read 读取文件
       byte[] bytes=new byte[1024];
       int len=0;
       while((len=fis.read(bytes))!=-1){
           fos.write(bytes,0,len);
       }
        //5  释放资源   先开的后关
        long ss = System.currentTimeMillis();
        fos.close();
        fis.close();
        System.out.println("复制图片用了"+(ss-s)+"毫秒");
    }
}
原文地址:https://www.cnblogs.com/liurui-bk517/p/11095458.html