Javax.imageio.IIOException: Unable to get input from URL!

I am writing code in java code to save images from specified links. It works fine basically, but for a while it throws an exception, i.e. "javax.imageio.IIOException: cannot get input stream from URL! in javax.imageio.ImageIO.read (ImageIO.java:1369)"

Whenever this exception throws, I check the URL in the browser, it will always be correct.

Please offer me some solution to solve this problem.

Thanks!

+4
source share
1 answer

So why remote connections have a reputation for being untrustworthy.

There may be several reasons for this, but it is best to consider these links as untrustworthy and determine how the application should behave.

I would use ThreadPoolExecutor and fetch the background image and extract them using Future. Since you can often fix this by repeating, run it to try again a couple of times.

You can wrap this class that returns the default image before loading the real image. You can then decide to retry the image in another session when it fails, despite trying to retry.

+1
source

All Articles