java – imageio.IIOException: Cant read input file

java – imageio.IIOException: Cant read input file

Have you tried using new File(logo.jpg); (without the leading /)?

And are you sure, the logo.jpg is copied to your output? (Some IDEs dont copy every file from your source-directories to your output (or target) directories.)

|-> Logo.jpg


|-> Window.class

(Note that the IDE/compiler does not copy the image to your output-directory and so the compiled code cannot find the image – allthough you did specify the correct path)

Try do debug which file resource you actually try to access. First step would be to get your new File(/logo.jpg).get [Canonical]Path() and print it to System.out (or alternatively watch in the the debugger). I guess the problem is the / before logo.jpg, which points to your root directory (e.g. c:) and your file isnt there, but I dont know your file setup in detail.

java – imageio.IIOException: Cant read input file

The problem is that youre looking at nothing before the image, so its looking into a folder that isnt there to find it.

You have to create a folder to store the images in your project, and then call to it, your folder name in front of the image name. e.g. File(Folder/Image.png));

Otherwise you can find the image by going through the entire directory, which isnt a good way as it takes longer, and when you move your project it wont be a working link as the directory will be different. For example: File(D:/eclipse/Workspace/Project/Folder/Image.png));

Creating a folder in your project so its on the same level as the source folder in the directory and call to it for the image, like so:

Folder structure;



Image Folder


Leave a Reply

Your email address will not be published.