How do I read image file?

Here you see a code sample to read an image file. This code will work either the image file is located in a file folder or inside a jar file. You can use javax.imageio.ImageIO class to read the image file.

package org.kodejava.awt;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

public class ReadingImage {
    public static void main(String[] args) {
        ReadingImage demo = new ReadingImage();

    public void getImage() {
        try {
            InputStream is = getClass().getResourceAsStream("/kodejava.png");
            BufferedImage image =;

            // Do something with the image.
        } catch (IOException e) {

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.