Search code examples
javafileubuntujavax.imageio

Java ImageIO: can't read input file


I don't know why this isn't working, but the program says it can't read the input file. This is also being run in Ubuntu, by the way:

Here is the sample code:

URI url = new URI("images/GUI/TitleScreen.PNG");
File file = new File(url.toString());           
bg = new ImageBackground(ImageIO.read(file));

The directory is located in the bin folder and src folder of the program as well.


Solution

  • What if you instead got your image as a stream from a resource? e.g.,

    String imgPath = "images/GUI/TitleScreen.PNG";
    BufferedImage buffImage = ImageIO.read(getClass().getResourceAsStream(imgPath));
    bg = new ImageBackground(buffImage);