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();
}
}