下载网络资源
程序员文章站
2022-03-02 21:13:01
...
public static void UrlDown() {
URL url = null;
String filePath = "";
try {
url = new URL("https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/[email protected]");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
filePath="1.png";
FileOutputStream fos = new FileOutputStream(filePath);
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, len);//写出
}
fos.close();
inputStream.close();
urlConnection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
上一篇: PHP网络资源弄视频,土办法
下一篇: PHP CURL 实现并发访问网络资源