首页 > 其他 > 详细

字节流批量下载图片代码实现

时间:2019-03-16 21:30:24      阅读:171      评论:0      收藏:0      [点我收藏+]
package com.zhangxueliang.demo;

import java.io.*;
import java.net.URL;
import java.util.Properties;

public class URLDemo {
    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        InputStream resourceAsStream = Object.class.getResourceAsStream("/imgs.properties");
        properties.load(resourceAsStream);
        InputStream is=null;
        OutputStream os = null;
        for (int i=1;i<=properties.size();i++){
            URL url = new URL((String) properties.get("img" + i));
            String file = url.getFile();
            System.out.println("==========> "+file);
            is = url.openStream();
            File f = new File("D:\\zhangxueliang\\images");
            if (!f.exists())
                f.mkdirs();
            os = new FileOutputStream(new File(f,i+".jpg"));
            int len;
            byte[] bys = new byte[1024];
            while ((len=is.read(bys))!=-1){
                os.write(bys,0,len);
            }
        }
        os.close();
        is.close();
    }
}

 

字节流批量下载图片代码实现

原文:https://www.cnblogs.com/niwotaxuexiba/p/10544359.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!