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
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);
createObjectURL() The URL. createObjectURL() static method creates a string containing a URL representing the object given in the parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object.
To create File object from Blob with JavaScript, we can use the File constructor`. const file = new File([blob], "filename"); to create a File object from a blob by putting it in an array.
Use Apache Common IO's FileUtils
:
import org.apache.commons.io.FileUtils FileUtils.copyURLToFile(url, f);
The method downloads the content of url
and saves it to f
.
Since Java 7
File file = Paths.get(url.toURI()).toFile();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With