| Author |
i cann't find any problem with this but it don't connect
|
Abhijith Sugunan
Greenhorn
Joined: Aug 04, 2012
Posts: 10
|
|
/*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
Ranch Hand
Joined: May 22, 2012
Posts: 449
|
|
It works for me:
Date : Fri Dec 28 09:58:59 CET 2012
Content Type : text/html; charset=UTF-8
|
 |
Abhijith Sugunan
Greenhorn
Joined: Aug 04, 2012
Posts: 10
|
|
|
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
Ranch Hand
Joined: May 22, 2012
Posts: 449
|
|
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
|
 |
 |
|
|
subject: i cann't find any problem with this but it don't connect
|
|
|