This Java tip illustrates a method of reading an Image from a file, inputStream, or URL. This tip also includes displaying of an image on the screen. Further, javax.imageio package is used to read an image from a file. This example works only above J2SE 1.4.

  Image image = null;
    try {
        // Read from a file
        File sourceimage = new File("source.gif");
        image =;
        // Read from an input stream
        InputStream is = new BufferedInputStream(
            new FileInputStream("source.gif"));
        image =;
        // Read from a URL
        URL url = new URL("");
        image =;
    } catch (IOException e) {
    // Use a label to display the image
    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);