zoukankan      html  css  js  c++  java
  • 利用IO流复制图片

    import java.io.*;
    
    public class CopyPicture {
        public static void main(String[] args) {
            //创建文件图片路径
            File i = new File("C:\Users\Administrator\Desktop\picture\a.png");//要拷贝的文件
            File o = new File("C:\Users\Administrator\Desktop\picture\b.png");//拷贝完的图片
            //创建流
            InputStream is = null;//输入流
            OutputStream os = null;//输出流
            try {
                is = new FileInputStream(i);
                os = new FileOutputStream(o);
                //拷贝的长度
                int len = -1;
                //缓存容器
                byte[] flush = new byte[1024];
                //从目标源读出
                while ((len = is.read(flush)) != -1) {
                    //写入
                    os.write(flush);
                    //刷新
                    os.flush();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
    
                //关闭输出流
                if (null != os) {
                    try {
                        os.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                //关闭输入流
                if (null != is) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
    
    
        }
    }
  • 相关阅读:
    bug
    UIFont
    OC
    iOS 之 多线程一
    OC 之 const
    我的读书单
    算法之回文数判断
    排序算法 之 一
    isEqual
    xcode 必用插件二
  • 原文地址:https://www.cnblogs.com/sunstudy/p/13088134.html
Copyright © 2011-2022 走看看