Comment on Tutorial - URLConnection sample program in Java By Ivan Lim



Comment Added by : gomz

Comment Added at : 2011-09-26 12:33:54

Comment on Tutorial : URLConnection sample program in Java By Ivan Lim
Very good example .. i ve written this program . Please help me.

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

int c;
URL hp=new URL("http://google.com");
URLConnection hpCon=hp.openConnection();
System.out.println("start");
System.out.println("Date: " + new Date(hpCon.getDate()));
System.out.println("Content-Type: " + hpCon.getContentType());
System.out.println("Expires: " + hpCon.getExpiration());
System.out.println("Last-Modified: " +new Date(hpCon.getLastModified()));
int len=hpCon.getContentLength();
System.out.println("length"+len);
if (len>0){
System.out.println("content--->");
InputStream ip=hpCon.getInputStream();
int i=len;
while (((c = ip.read()) != -1) && (-i > 0)) {
System.out.print((char) c);
}
ip.close();
}
else{
System.out.println("Content not available");
}
}

For which my out put is :

start
Date: Thu Jan 01 01:00:00 GMT 1970
Content-Type: null
Expires: 0
Last-Modified: Thu Jan 01 01:00:00 GMT 1970
length-1
Content not available


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. thank you so much. i've been fixing this problem o
View Tutorial          By: yo at 2011-06-05 13:25:37

2. int n = 0;
for (int m = 0; m < 5; m++) {

View Tutorial          By: max at 2011-05-26 09:41:26

3. Great Work for JAVA Beginners
View Tutorial          By: Sudhir Rajgure at 2009-03-01 02:40:00

4. the default construrctor does not give the defalut
View Tutorial          By: muhammad abdullah at 2011-04-11 13:16:20

5. scriptlets when used in a page - helper pattern...
View Tutorial          By: tony at 2009-03-04 17:03:03

6. Hi ,Razvan

I changed code as in you

View Tutorial          By: sanil at 2011-01-01 11:05:53

7. Thanx u m at lab..n u made me complete my prog!
View Tutorial          By: Liza at 2009-12-09 23:03:51

8. the discussion is not enogh
View Tutorial          By: gulstan at 2011-03-27 03:47:24

9. Highly appreciatable.Excellent Docs.
View Tutorial          By: Debi P Naik at 2010-05-04 05:55:45

10. Java s ssssss
View Tutorial          By: zoya at 2012-04-27 12:24:59