I made a program in selenium that extracts links of some images from a website so after extraction of link i wanted to save all those images in a folder so i wrote a little code for that
for(int j=0; j<links.size(); j++) { URL imageURL = new URL(linklist[j]); BufferedImage saveImage = ImageIO.read(imageURL); ImageIO.write(saveImage, "png", new File("C:\\Users\\Dumpty\\Desktop\\Output\\logo-forum"+ j +".png")); }
and yeah im using array to store the url's and for confirmation i printed all the links with this code
for(int k=0; k<links.size(); k++) { System.out.println(linklist[k]); }
all seems to be working fine but in extraction im facing problem, im getting Can't get input stream from URL! Error I also tried this Can't get input stream from URL! Java but it's still not working this is the full view of the error im getting
Exception in thread "main" javax.imageio.IIOException: Can't get input stream from URL! at javax.imageio.ImageIO.read(Unknown Source) at com.phantomjs.phantomJStest.main(phantomJStest.java:58) Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://lh3.googleusercontent.com/f_kendBNnYqba-mMV-3ItGZ2zzbChaaV22nE4uaEW92EWtXPzvFYwDk82AKQ6YlOru4=w1440-h620 2x at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source) at java.net.URL.openStream(Unknown Source) ... 2 more
#java #image #selenium