Getting an Image from a URL - Java Network

Java examples for Network:URL

Description

Getting an Image from a URL

Demo Code

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
  public static void main(String[] args) {
    try {//from  ww  w  .  ja  va2s . c o m
      // Create a URL for the image's location
      URL url = new URL("http://hostname:80/image.gif");

      // Get the image
      java.awt.Image image = java.awt.Toolkit.getDefaultToolkit()
          .getDefaultToolkit().createImage(url);
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
  }
}

Related Tutorials