Here you can find the source of downloadImage(URL url)
public static BufferedImage downloadImage(URL url)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import javax.imageio.ImageIO; public class Main { public static BufferedImage downloadImage(URL url) { try {// ww w . java2 s. c om InputStream in = new BufferedInputStream(url.openStream()); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int n = 0; while (-1 != (n = in.read(buf))) { out.write(buf, 0, n); } out.close(); in.close(); byte[] byteArray = out.toByteArray(); ByteArrayInputStream inByte = new ByteArrayInputStream(byteArray); BufferedImage read = ImageIO.read(inByte); return read; } catch (IOException ioe) { ioe.printStackTrace(); } return null; } }