Groovy从URL下载图片 [英] Groovy download image from URL
本文介绍了Groovy从URL下载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道从这个RUL下载图像的正确方法是: http://www.hidemyass.com/proxy-list/img/port/7018246/1
I am wondering what the proper way to go about downloading the image from this RUL would be: http://www.hidemyass.com/proxy-list/img/port/7018246/1
我试过的方式下载它,以未知格式离开文件。我测试过的当前代码片段是:
The way I tried downloading it, leaves the file in an unknown format. Current code snippet I tested out is:
public void download(def address) {
def file = new FileOutputStream(address.tokenize("/")[-1])
def out = new BufferedOutputStream(file)
out << new URL(address).openStream()
out.close()
}
推荐答案
这是否工作?我相信它应该:
Does this work? I believe it should:
public void download(def address) {
new File("${address.tokenize('/')[-1]}.png").withOutputStream { out ->
out << new URL(address).openStream()
}
}
这篇关于Groovy从URL下载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文