0

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
tdammon
  • 599
  • 1
  • 7
  • 26
  • Try another image. Do you get the same problem? – DevilsHnd - 退職した Nov 04 '17 at 20:06
  • `Exception in thread "main" java.io.IOException: king_of_hearts.png is not readable!` comes up when your code is not able to find the image at the specified location, try providing the complete path as in `/Pictures/image_name.png` – isank-a Nov 04 '17 at 20:09

0 Answers0