public void download() {
String destination = "E:/home/haha/b.jpg";
URL url = null;
try {
url = new URL("http://zhang-pay-test.oss-cn-shanghai.aliyuncs.com//miniapplets/2020/09/23/8378b32af7efb65e2db0968da04c4e39.jpg");
DataInputStream dataInputStream = new DataInputStream(url.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(new File(destination));
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = dataInputStream.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
fileOutputStream.write(output.toByteArray());
dataInputStream.close();
fileOutputStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
根据url下载图片
最新推荐文章于 2022-12-07 16:06:57 发布