开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜