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. nice information, thanks dost.
View Tutorial          By: Bhargavi Menpara at 2013-02-12 08:11:23

2. could somebody please tell a case where memcpy() w
View Tutorial          By: freak at 2011-02-09 20:29:26

3. yes simple good it wroking goog
View Tutorial          By: durga prasad pavirala at 2009-02-11 03:43:04

4. I got Error...Why it is happen..??


View Tutorial          By: Dineth at 2011-07-15 16:54:31

5. hi,
can you tell me how to run the code to

View Tutorial          By: raghu at 2008-12-26 03:15:52

6. To "need help":

String s

View Tutorial          By: Mike at 2010-10-14 20:09:31

7. i like google
View Tutorial          By: parikh dhruti at 2013-02-12 06:43:19

8. it's really Nice Clock
View Tutorial          By: Mido at 2007-09-09 08:45:49

9. So, is it possible to use the getClass() and getRe
View Tutorial          By: cee at 2014-11-29 14:27:10

10. Hi,
I am getting this exception..My modem i

View Tutorial          By: puneet at 2010-04-22 10:22:18