I am trying to create an object with a png image property. I a code to test if the image is readable. My code tells me the image is not readable. Is there a way to make the image readable or do I need to find a new image?
System.out.println(new File("king_of_hearts.png").getAbsolutePath()); // Try this to pinpoint your issue
File king = new File("king_of_hearts.png");
if(king.canRead()){ // Check if your file exists and is readable before you use it
BufferedImage KingOfAxes = ImageIO.read(new File("king_of_hearts.png"));
} else{
throw new IOException(king.getName() + " is not readable!"); // Not readable -> Throw exception
}
System.out.println("King");
The result is this:
C:\Users\trevo\Desktop\Testcode\king_of_hearts.png
Exception in thread "main" java.io.IOException: king_of_hearts.png is not readable!
at com.company.Main.main(Main.java:20)
Process finished with exit code 1