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. Excellent Example...... To understand the concept
View Tutorial          By: SUNNY at 2009-02-24 23:41:04

2. I got a project on J2ME and i was to start to kno
View Tutorial          By: md kadir ali , vit university , vellore at 2010-05-12 00:59:58

3. while i am executing this program i am getting Nul
View Tutorial          By: Seema at 2013-11-26 18:39:15

4. Good Tutorial.
Thanks.

View Tutorial          By: Oki Wicaksono at 2012-05-29 04:09:05

5. i get this error too.
: Parent: child proce

View Tutorial          By: Anon at 2009-02-25 08:30:58

6. give the picture view of connecting vb.net with my
View Tutorial          By: Murugamani at 2014-09-09 06:12:58

7. /** Example shows garbage collector in action

View Tutorial          By: sreekar at 2010-05-08 07:58:09

8. How to download a pdf file from the server and sav
View Tutorial          By: harsha at 2013-08-12 07:52:22

9. Nice basics. Very helpful
View Tutorial          By: Gorav at 2011-11-11 12:46:28

10. Hi, my name is Jaime,
I wan't to do a jsp w

View Tutorial          By: Jaime at 2011-10-24 12:47:50