/**
* 根据url下载文件流
* @param urlStr
* @return
*/
public static InputStream getInputStreamFromUrl(String urlStr) {
InputStream inputStream=null;
try {
//url解码
URL url = new URL(java.net.URLDecoder.decode(urlStr, "UTF-8"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(3 * 1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//得到输入流
inputStream = conn.getInputStream();
} catch (IOException e) {
}
return inputStream;
}
06-16
930

07-22
1万+

“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交
评论




查看更多评论

打赏作者
¥2
¥4
¥6
¥10
¥20
输入1-500的整数



