java 图片到本地,java下载图片到本地实例
发布日期:2021-06-24 13:06:03 浏览次数:3 分类:技术文章

本文共 975 字,大约阅读时间需要 3 分钟。

正版疯狂java讲义第5版编程教材

80.6元

(需用券)

去购买 >

ce6f3cef5376f6874bdc7dc12ae71cd5.png

public static void main(String[] args) {

String ImageUrl = "xxxxxxxxx";//图片url

String path="F://createVerifyCode.jpg";//  保存地址

downloadPic(ImageUrl ,path);

}

//链接url下载图片

public static boolean downloadPic(String urlList,String path) {

URL url = null;

try {

url = new URL(urlList);

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();

return true;

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return false;

}

原文链接:http://st4024589553.iteye.com/blog/2425548

java程序设计与数据结构(第4版)

116.1元

包邮

(需用券)

去购买 >

1bfc949d131c9dd9018581360eb2222f.png

转载地址:https://blog.csdn.net/weixin_32946543/article/details/115782595 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java迷宫寻宝,迷宫寻宝
下一篇:php去掉所有,php如何去掉所有标签

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年03月31日 08时09分32秒