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



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. excellent for a beginer in inet address ...
View Tutorial          By: Tony at 2009-08-13 22:39:48

2. it would be very helpful if you demonstrated how t
View Tutorial          By: newcoder at 2011-10-24 17:40:25

3. I 've tried the program for Bubble Sort. This prog
View Tutorial          By: Siva at 2012-04-17 05:19:28

4. it very usefull to introduse the j2me to me

View Tutorial          By: Sudhir at 2011-08-31 13:05:40

5. i m new in java plz send some programs on packages
View Tutorial          By: zainul hasan mirza at 2009-08-31 02:28:32

6. excellent code.....
View Tutorial          By: Anonymous at 2009-05-07 03:09:01

7. we generally use this keyword for referring to the
View Tutorial          By: madhu at 2012-02-07 14:11:57

8. i am looking for the samples in java programming u
View Tutorial          By: mary grace leron at 2010-02-18 01:50:50

9. Good explanation with simple language and style. N
View Tutorial          By: Ismail. MC at 2009-03-31 04:46:04

10. Many many thanks. It is very very helpful. Again t
View Tutorial          By: Mehedi Hasan at 2009-09-15 21:41:51