public static void UrlDown() {
URL url = null;
String filePath = "";
try {
url = new URL("https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/baiduyun@2x-e0be79e69e.png");
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();
}
}
下载网络资源
最新推荐文章于 2020-11-21 18:56:49 发布