public static void main(String[] args) {
String photoUrls = "";
String[] PhotoUrl = photoUrls.split(",");
List<String> errorUrl = Lists.newArrayList();
int i = 0;
for (String urlString : PhotoUrl) {
++i;
System.out.println(i);
URL url = null;
URLConnection con = null;
InputStream is = null;
OutputStream os = null;
try {
url = new URL(urlString);
// 打开连接
con = url.openConnection();
con.setConnectTimeout(5 * 1000);
is = con.getInputStream();
byte[] bs = new byte[1024];
int len;
File sf = new File("/Users/fzs/photo/");
if (!sf.exists()) {
sf.mkdirs();
}
os = new FileOutputStream(sf.getPath() + "\\" + i + ".jpg");
// 开始读取
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
}
os.close();
is.close();
} catch (IOException e) {
errorUrl.add(urlString);
}
}
System.out.println(errorUrl);
}