如何从 URL 对象(图像)创建文件对象
2022-08-31 10:21:55
我需要从URL对象创建一个File对象我的要求是我需要创建一个网络图像的文件对象(比如谷歌徽标)
URL url = new URL("http://google.com/pathtoaimage.jpg");
File f = create image from url object
我需要从URL对象创建一个File对象我的要求是我需要创建一个网络图像的文件对象(比如谷歌徽标)
URL url = new URL("http://google.com/pathtoaimage.jpg");
File f = create image from url object
import org.apache.commons.io.FileUtils
FileUtils.copyURLToFile(url, f);
该方法将下载 的内容并将其保存到 。url
f
自 Java 7 起
File file = Paths.get(url.toURI()).toFile();