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. In this examples please create the output of the p
View Tutorial          By: bheemesh at 2011-05-01 09:05:46

2. Hi guys, What is the best way to connect to mysql
View Tutorial          By: veron at 2010-09-11 16:13:25

3. helpfull !!!!
View Tutorial          By: Anonymous at 2009-05-12 03:48:15

4. HI,
I want to send an sms via website to mo

View Tutorial          By: Hemant at 2008-11-04 05:26:30

5. Very good tutorial!
View Tutorial          By: Herve at 2011-04-04 08:06:21

6. Exception in thread "main" java.lang.NoC
View Tutorial          By: RobustTm at 2008-12-18 23:19:46

7. code givr an error when sending the Email:

View Tutorial          By: Ravi Shanker Yadav at 2013-05-08 12:36:59

8. hi I am execute this code But message can't send <
View Tutorial          By: Sudhir Patil at 2011-02-01 10:28:28

9. To the,
sir/mam, i want to do java certific

View Tutorial          By: CERTIFICATION OF JAVA at 2011-03-03 02:27:05

10. Nice Intro to start J2Me
View Tutorial          By: Mak at 2009-07-04 10:36:00