Connecting Tech Pros Worldwide Forums | Help | Site Map

Plz help me on this code

Newbie
 
Join Date: Jun 2009
Posts: 7
#1: Jul 20 '09
I hav written the program in Java to download the details from the server....as follows....
Expand|Select|Wrap|Line Numbers
  1. import java.net.*;
  2. import java.io.*;
  3. import java.util.Date;
  4. class urldemo
  5. {
  6.  public static void main(String args[])throws Exception
  7.  {
  8.   int c;
  9.   URL hp=new URL("http://www.yahoo.com");
  10.   URLConnection hpcon=hp.openConnection();
  11.   long d=hpcon.getDate();
  12.   if(d==0)
  13.   System.out.println("no date");
  14.   else
  15.   System.out.println("Date:"+new Date(d));
  16.   System.out.println("Content Type:"+hpcon.getContentType());
  17.   d=hpcon.getExpiration();
  18.   if(d==0)
  19.   System.out.println("No expire info:");
  20.   else
  21.   System.out.println("Expires on:"+new Date(d));
  22.   d=hpcon.getLastModified();
  23.   if(d==0)
  24.   System.out.println("No modified info:");
  25.   else
  26.   System.out.println("Modified on:"+new Date(d));
  27.   int len=hpcon.getContentLength();
  28.   if(len==-1)
  29.   System.out.println("No length");
  30.   else
  31.   System.out.println("Content Length"+len);
  32.   if(len!=0)
  33.   {
  34.    System.out.println("===============CONTENT==================");
  35.    InputStream input=hpcon.getInputStream();
  36.    int i=len;
  37.    while(((c=input.read())!=-1))
  38.    {
  39.     System.out.print((char)c);
  40.    }
  41.    input.close();
  42.   }
  43.   else
  44.   {
  45.    System.out.println("Content Unavailable");
  46.   }
  47.  }
  48. }
  49.  
But i did not get the output for that....I am getting the error like "Unknownhost Exception"....Kindly assist me on that....

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Jul 20 '09

re: Plz help me on this code


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
Newbie
 
Join Date: Jun 2009
Posts: 7
#3: Jul 22 '09

re: Plz help me on this code


Thank you....
Last year i have done the same program...It was working fine...
But now only its not working....
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#4: Jul 22 '09

re: Plz help me on this code


Quote:

Originally Posted by sreekandank View Post

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
Reply