Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i cann't find any problem with this but it don't connect

 
Abhijith Sugunan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/*Always i get
No Date Avaliable
Content Type : null
*/


import java.net.*;
import java.io.*;
import java.util.Date;

class urlTest {

public static void main(String [] args) throws Exception {

URL url = new URL("http://www.internic.net");

URLConnection con = url.openConnection();

// getting date

long date = con.getDate();
if(date==0)
System.out.println("No Date Avaliable");
else
System.out.println("Date : "+ new Date(date));

// Getting content type of the page

System.out.println("Content Type : "+con.getContentType());




}


}
 
Ivan Jozsef Balazs
Rancher
Posts: 979
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works for me:

Date : Fri Dec 28 09:58:59 CET 2012
Content Type : text/html; charset=UTF-8
 
Abhijith Sugunan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is some thing wrong with my JDK .I got this program correct on another computer . Which version of the JDK are you using IVAN..And when i tried it in a online editor then also i couldn't get the output..Anyway thanks for your replay..
 
Ivan Jozsef Balazs
Rancher
Posts: 979
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

C:\temp\sme>java15 -version

C:\temp\sme>C:\langs\java\jdk1.5.0_18\bin\java.exe -version
java version "1.5.0_18"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_18-b02)
Java HotSpot(TM) Client VM (build 1.5.0_18-b02, mixed mode)

C:\temp\sme>java15 urlTest

C:\temp\sme>C:\langs\java\jdk1.5.0_18\bin\java.exe urlTest
Date : Fri Dec 28 13:50:12 CET 2012
Content Type : text/html; charset=UTF-8

C:\temp\sme>java16 -version

C:\temp\sme>"C:\langs\java\jdk1.6.0_37\bin\java.exe" -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)

C:\temp\sme>java16 urlTest

C:\temp\sme>"C:\langs\java\jdk1.6.0_37\bin\java.exe" urlTest
Date : Fri Dec 28 13:50:20 CET 2012
Content Type : text/html; charset=UTF-8

C:\temp\sme>java17 -version

C:\temp\sme>"C:\langs\java\jdk1.7.0_10\bin\java.exe" -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) Client VM (build 23.6-b04, mixed mode, sharing)

C:\temp\sme>java17 urlTest

C:\temp\sme>"C:\langs\java\jdk1.7.0_10\bin\java.exe" urlTest
Date : Fri Dec 28 13:50:34 CET 2012
Content Type : text/html; charset=UTF-8
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic