Unknown host exception error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreekandank
    New Member
    • Jun 2009
    • 45

    Unknown host exception error

    I hav written the program in Java to download the details from the server....as follows....
    [code=java]
    import java.net.*;
    import java.io.*;
    import java.util.Date;
    class urldemo
    {
    public static void main(String args[])throws Exception
    {
    int c;
    URL hp=new URL("http://www.yahoo.com") ;
    URLConnection hpcon=hp.openCo nnection();
    long d=hpcon.getDate ();
    if(d==0)
    System.out.prin tln("no date");
    else
    System.out.prin tln("Date:"+new Date(d));
    System.out.prin tln("Content Type:"+hpcon.ge tContentType()) ;
    d=hpcon.getExpi ration();
    if(d==0)
    System.out.prin tln("No expire info:");
    else
    System.out.prin tln("Expires on:"+new Date(d));
    d=hpcon.getLast Modified();
    if(d==0)
    System.out.prin tln("No modified info:");
    else
    System.out.prin tln("Modified on:"+new Date(d));
    int len=hpcon.getCo ntentLength();
    if(len==-1)
    System.out.prin tln("No length");
    else
    System.out.prin tln("Content Length"+len);
    if(len!=0)
    {
    System.out.prin tln("========== =====CONTENT=== =============== ");
    InputStream input=hpcon.get InputStream();
    int i=len;
    while(((c=input .read())!=-1))
    {
    System.out.prin t((char)c);
    }
    input.close();
    }
    else
    {
    System.out.prin tln("Content Unavailable");
    }
    }
    }
    [/code]

    But i did not get the output for that....I am getting the error like "Unknownhos t Exception"....K indly assist me on that....
    Last edited by Nepomuk; Jul 21 '09, 09:11 PM. Reason: Please use [code]...[/code] tags
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    It works for me; you must be behind a firewall or have no internet connection at all. Check it, this is not a Java problem.

    kind regards,

    Jos

    Comment

    • sreekandank
      New Member
      • Jun 2009
      • 45

      #3
      Thank you....
      Last year i have done the same program...It was working fine...
      But now only its not working....

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by sreekandank
        Thank you....
        Last year i have done the same program...It was working fine...
        But now only its not working....
        As I wrote above: this is not a Java problem: the IP address could not be found given the host name; check your DNS server address.

        kind regards,

        Jos

        Comment

        Working...