How to create file object from URL object (image)

java

Solution

You can make use of `ImageIO` in order to load the image from an URL and then write it to a file. Something like this:

URL url = new URL("http://google.com/pathtoaimage.jpg");
BufferedImage img = ImageIO.read(url);
File file = new File("downloaded.jpg");
ImageIO.write(img, "jpg", file);

This also allows you to convert the image to some other format if needed.

Problem

I need to create a File object from URL object My requirement is I need to create a file object of a web image (say googles logo) ``` URL url = new URL("http://google.com/pathtoaimage.jpg"); File f = create image from url object ```

Original source

Related problems