开发者

javax.imageio.IIOException: Can't get input stream from URL!

开发者 https://www.devze.com 2023-01-17 23:47 出处:网络
I write a code in java code to save images from specified links. It works fine mostly, but some time it throws an exception ie

I write a code in java code to save images from specified links. It works fine mostly, but some time it throws an exception ie "javax.imageio.IIOException: Can't get input stream from URL! at javax.imageio.ImageIO.read(ImageIO.java:1369)"

When开发者_JAVA百科ever this exception throws I check the url in browser, it will correct always.

Please suggest me some solution to solve this problem.

Thanks!


Well, that's why remote connections have the reputation for being unreliable.

There can be several reasons for this, but best is to treat these links as unreliable and define how your application should behave.

I would use a ThreadPoolExecutor and to execute fetching the image on the background and retrieving them with a Future. Since you can often correct it by retrying, running it is a loop to retry a couple of times.

You can wrap this is a class which returns a default image till the real image is loaded. You can then still decide to retry fetching the image in another session when it fails despite of the retry attempts.

0

精彩评论

暂无评论...
验证码 换一张
取 消