标签:获得 put public exception output read 通过 doc stream
@Test
public void loadImage() throws IOException{
String url = "https://3w.huanqiu.com/a/a-XDI128434DD0215D7A70F8?agt=8/";
Connection con = Jsoup.connect(url);
Document document = con.get();
Elements select = document.select("div a img");
int i = 1;
for(Element s:select){
String attr = s.attr("src");
System.out.println(attr);
URL u = new URL(attr);
//通过url来获得输入流,用来将网页中的数据传输到程序中
InputStream is = u.openStream();
//一次读取文件的大小
byte[] data = new byte[1024];
//截取最后一个点后缀
String st = i+attr.substring(attr.lastIndexOf("."));
i++;
System.out.println(st);
FileOutputStream fo = new FileOutputStream(new File(st));
int len = -1;
while((len=is.read(data))!=-1){
fo.write(data, 0, len);
System.out.println("OK");
}
}
}
标签:获得 put public exception output read 通过 doc stream
原文地址:https://www.cnblogs.com/xiaokaivip/p/9152574.html