java的imagelcon_Java中的ImageIcon更新(来自互联网)?

我有一些带有图像的URL.此图像在每个请求期间更新(即,对(相同)URL的每个请求都返回一个新图像).比如说,这个URL指向CAPTCHA.

我的目标是在我的程序中加载和显示几个这样的图像.

以下代码将这些图像加载到我的本地文件系统并且工作正常(即,所有图像都不同,唯一):

String filePath;

String urlPath;

int numOfFilesToDownload;

//Here filePath and urlPath are initialized.

//filePath points to the directory, where to save images

//urlPath is the url from where to download images

//numOfFilesToDownload is the number of files to download

for(int i = 0; i < numOfFilesToDownload; i++){

//Initializing connection

URL url = new URL(urlPath);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

//Downloading image

try(InputStream is = conn.getInputStream();

FileOutputStream os = new FileOutputStream(filePath + "img" + i + ".jpg")){

int b;

<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值