Extracting Images from Internet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashsa
    New Member
    • Feb 2007
    • 45

    Extracting Images from Internet

    Hi,

    Am trying to extract an image from a URL as follows:

    Code:
     
    try
    {
    BufferedImage input = ImageIO.read(new URL("http://www.google.co.in/images/close_sm.gif"));
    File outputFile = new File("image.png");
    ImageIO.write(input, "PNG", outputFile);
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    The URL is a valid one. But still I get the following error :
    Code:
     javax.imageio.IIOException: Can't get input stream from URL!
    Any idea where I am going wrong ?
    Thanks for any help ..
  • ashsa
    New Member
    • Feb 2007
    • 45

    #2
    Got it !!
    Jus gotta set my server's proxy settings.
    Included
    Code:
     System.setProperty("http.proxyHost","xyz.com"); 
    System.setProperty("http.proxyPort", 8080);
    before creating the BufferedImage and it works fine :-)
    An alternative to this could be specifying the proxy details thru command prompt during execution.
    Eg:
    Code:
    java -Dhttp.proxyHost=xyz.com -Dhttp.proxyPort=8080 MyJavaClass

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by ashsa
      Got it !!
      Jus gotta set my server's proxy settings.
      Included
      Code:
       System.setProperty("http.proxyHost","xyz.com"); 
      System.setProperty("http.proxyPort", 8080);
      before creating the BufferedImage and it works fine :-)
      An alternative to this could be specifying the proxy details thru command prompt during execution.
      Eg:
      Code:
      java -Dhttp.proxyHost=xyz.com -Dhttp.proxyPort=8080 MyJavaClass
      Very good work indeed.

      Comment

      Working...