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. Clear explaination..Thank You Sir...
View Tutorial          By: nishanth at 2014-06-16 08:58:04

2. Hi i copied the same code n change the comport no
View Tutorial          By: Nidhi Puri at 2010-12-04 00:55:29

3. The code gives the following exception :-
<

View Tutorial          By: swetha at 2009-03-12 07:19:23

4. Excellent explanation. How can I take input from t
View Tutorial          By: Joe at 2013-03-31 11:02:28

5. It seems author has half knowlage
EJB main

View Tutorial          By: Aryan Siddharth Singh Gautam at 2010-03-22 03:40:11

6. nice tutorial,but if provided with the complete ex
View Tutorial          By: Prasant Kumar Sahu at 2013-01-07 13:17:20

7. Hibernate with annotations and QBE api reduced our
View Tutorial          By: Andrew at 2011-04-29 10:34:26

8. Your Crystal report viewer showing all the records
View Tutorial          By: Neel at 2013-06-09 15:02:15

9. can any beginners can try creating web pages

View Tutorial          By: jo at 2015-07-28 19:35:11

10. i think this ist perfectly fine :) if you don't kn
View Tutorial          By: julian at 2011-03-07 05:54:08