Axel Carré
Axel Carré

Reputation: 313

ImageIO.readImage IIOException while I can open it in Chrome

I can open this image in my browser but it won't load in my java application, why? It is supposed to be a free-to-use database, I can't see why I can't use it.

I'm using this piece of code:

public static String getContentsFromURL(String address){

    String contents = "";
    try{
        URL url = new URL(address);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        while((line = bufferedReader.readLine()) != null){
            contents += line;
        }
        bufferedReader.close();
    }catch(IOException e){
        e.printStackTrace();
    }
    return contents;

}

And I'm getting an IIOException "Can't find input file!"

Upvotes: 0

Views: 32

Answers (1)

George Weekson
George Weekson

Reputation: 483

try this code

URL url = new URL("http://ddragon.leagueoflegends.com/cdn/9.20.1/img/champion/Gragas.png");
Image image1 = ImageIO.read(url);

image screenshot from my debbuger. enter image description here

Upvotes: 1

Related Questions