Download and save image from a url   #


import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.URL; /** * Download and image file png/jpg from an external url and store it locally to a given folder (/tmp in this case). */ class ImageDownloader { public static void main(String[] args ) { BufferedImage image =null; try{ // url of the image to download URL url =new URL("https://www.codercrunch.com/images/logo-cc.png"); // read the url image = ImageIO.read(url); //for png ImageIO.write(image, "png",new File("/tmp/logo-cc.png")); // for jpg ImageIO.write(image, "jpg",new File("/tmp/logo-cc.jpg")); System.out.println("ok"); }catch(IOException e) { e.printStackTrace(); } } }

Loading Please Wait...