复制图片 CopyImages

 

 

 

实现代码

 

复制代码
package Zuoye01;

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

public class ImagesCopy {

    public static void main(String[] args) {
        
        
        
        

        //实现复制粘贴图片的功能
        
        //1 地址  2 FileInput..  FileOut...
        //要复制粘贴要先读取   Input 
        
        FileInputStream fis = null;
        FileOutputStream fos = null;
        
        
        try {
            fis = new FileInputStream("C:/MyDemo/1.jpg");
            fos = new FileOutputStream("C:/MyDemo/2.jpg");
            
            int num = -1;
            try {
                while((num = fis.read())!=-1) {
                    
                    fos.write(num);
                    
                    fos.flush();
                    
                }
                
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            
            try {
                if(fos!=null) {
                fos.close();
                }
                try {
                    if(fis!=null) {
                    fis.close();
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
        }
        
        
    }

}
复制代码

 

 

 

 

本文作者:AxeBurner

本文链接:https://www.cnblogs.com/bichen-01/p/11291443.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   AxeBurner  阅读(228)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.