The “javax.imageio” package is used to deal with the Java image stuff. Here’s two “ImageIO” code snippet to read an image file.

1. Read from local file

File sourceimage = new File("c:\\mypic.jpg");
Image image =;

2. Read from URL

URL url = new URL("");
Image image =;

ImageIO Example

In this example, you will use ImageIO to read a file from an URL and display it in a frame.

package com.mkyong.image;
import java.awt.Image;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ReadImage 
    public static void main( String[] args )
    	Image image = null;
        try {
            URL url = new URL("");
            image =;
        } catch (IOException e) {
        JFrame frame = new JFrame();
        frame.setSize(300, 300);
        JLabel label = new JLabel(new ImageIcon(image));


Tags :
Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Related Posts

Popular Posts