I am reading an image directly from url. I am using this image in web service. Now if the image is not available my service breaks and if the image is available my service is working fine. I am wondering if there is a way I can check if the image is exists or not. I would appreciate if someone can help me to solve this issue.
Sam Saha wrote:Now if the image is not available my service breaks
According to the javadocs, ImageIO.read throws an IOException if there's a problem reading from the URL. If you catch that you can execute whatever alternative code is appropriate.
not sure what kind of try/catch your code is surrounded with, but I was able to get this to work:
when the bad url is uncommented, it throws an IO exception and just skips the null check...so maybe you just need code to deal with a non-existent image in the catch block.