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. hi, good afternoon
i don,t know how to use

View Tutorial          By: Hemanshu at 2012-01-17 06:49:10

2. Good work, IT really help me a lot;
View Tutorial          By: TUSHAR at 2010-02-03 01:25:37

3. Hello
I installed Android in eclipse...only

View Tutorial          By: amit kumar at 2012-01-19 11:04:55

4. Hi all, i have tried above code, but am getting fo
View Tutorial          By: shalini Iyer at 2008-04-22 01:20:32

5. i have a program in which we have to find the summ
View Tutorial          By: Navjyot at 2013-01-28 10:38:55

6. Sir your example is god
but i am surprisin

View Tutorial          By: Ata Ul Nasar at 2011-06-05 16:23:09

7. Good Example esp. way it was presented.
View Tutorial          By: Arunlal at 2013-06-20 11:56:43

8. I need a software to send messages to our members.
View Tutorial          By: M V Bhaktha at 2012-05-22 08:19:38

9. Thanks for the tips.

I hesitated to

View Tutorial          By: Dick at 2011-10-09 15:21:50

10. Hey..can anyone please tell me how to run linux co
View Tutorial          By: ahmed at 2008-09-05 10:22:52