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. pls give me code for exact communication between
View Tutorial          By: SIRAJ at 2009-02-19 06:24:10

2. This tutorial is good for beginners. If you provid
View Tutorial          By: Sateesh Bobby at 2008-12-09 23:56:18

3. Good Article. Small and Sweet...
View Tutorial          By: Anupam Pawar at 2009-05-27 03:04:08

4. i really hate do while loop statement, can u pls h
View Tutorial          By: mARjO at 2011-09-01 03:50:18

5. good example
View Tutorial          By: WANT TO KNOW WHY WE USE APPEND at 2011-06-14 00:39:48

6. 27: What happens if the producer and the customer
View Tutorial          By: Spender at 2010-07-25 14:42:08

7. haii...
I am Ahmed , i am in 3rd btech ,

View Tutorial          By: Ahmed at 2014-08-09 06:30:11

8. To determine current location in a file:
{<

View Tutorial          By: Terry at 2009-09-27 13:15:56

9. Thank you!!
View Tutorial          By: Diego at 2015-07-16 21:11:58

10. really very-2 good site....

thanks

View Tutorial          By: Priti at 2012-02-06 03:00:13