根据图片地址下载图片到本地
原创
©著作权归作者所有:来自51CTO博客作者安详的苦丁茶的原创作品,请联系作者获取转载授权,否则将追究法律责任
public static void main(String[] args) {
String urls = "http://rongcloud-web.qiniudn.com/docs_demo_rongcloud_logo.png";
String path = "d:/pic.png";
try {
URL url = new URL(urls);
DataInputStream dataInputStream = new DataInputStream(url.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
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 (IOException e) {
e.printStackTrace();
}
}