View Single Post
  #2 (permalink)  
Old 01-18-2008, 10:07 PM
hardwired hardwired is online now
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
How to download images using Java
Code:
import java.awt.image.BufferedImage; import java.io.*; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.*; public class DownloadImage { public static void main(String[] args) throws IOException { String path = "http://www.java-forums.org/images/ca_evo/misc/logo.gif"; URL url = new URL(path); InputStream stream = url.openConnection().getInputStream(); BufferedImage image = ImageIO.read(stream); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JLabel(new ImageIcon(image), JLabel.CENTER)); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } }
Reply With Quote