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. because equals method compares on object reference
View Tutorial          By: mohit s. at 2011-12-24 06:29:35

2. Please assist me in getting the code to read messa
View Tutorial          By: Jaydatta at 2009-04-05 23:24:57

3. what is the usage of 'detail' and 'debug' init par
View Tutorial          By: uday at 2011-07-21 04:53:02

4. Simpler example:

import java.io.*;

View Tutorial          By: Joseph Harner at 2011-12-04 23:20:48

5. This is an old method although it works. The bette
View Tutorial          By: Emiley at 2013-01-11 03:56:02

6. Great ! done a gud job
View Tutorial          By: Manju at 2012-11-02 06:43:58

7. very good cod
View Tutorial          By: moly at 2007-03-13 08:17:40

8. Why not a simple array list of threads?
wha

View Tutorial          By: Ranadheer Machineni at 2011-08-18 12:30:35

9. hi all m getting following error ,
can anyo

View Tutorial          By: raj at 2008-11-04 21:46:12

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