Eclipse bug : javax.imageio.IIOException: Can't read input file

paraguma picture paraguma · Aug 21, 2012 · Viewed 16.7k times · Source

The following code is running successfully in BlueJ IDE, but not in Eclipse.

String path="images/pic1.jpg";

BufferedImage myPicture = null;
    try {
        myPicture = ImageIO.read(new File(path));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

My image path is same in both the IDE. Also, I observed directory structure is same for *.class file and image files.

Why this happens in eclipse only?

Answer

Prasad picture Prasad · Apr 5, 2013

You must use

System.getProperty("user_dir")+File.separator+"image"+File.separator+"im0001.jpg";