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. xml response is :

<?xml version=

View Tutorial          By: Madhu at 2011-06-29 09:47:51

2. i have been trained in java stream. But i dont kno
View Tutorial          By: savio at 2013-01-23 10:15:51

3. Please provide some more examples ...It will be ve
View Tutorial          By: it interview questions at 2012-09-29 05:07:55

4. How to send to multiple mobiles at a time
View Tutorial          By: rakesh at 2010-04-30 10:33:51

5. hi! i want to know about how database createed in
View Tutorial          By: kundan at 2010-05-19 05:03:33

6. Yes, you can use the newer one as follows

View Tutorial          By: John at 2012-08-11 01:40:46

7. Thanks a ton! :)
View Tutorial          By: Prateek at 2015-03-12 11:40:08

8. this is really very useful because of this site i
View Tutorial          By: meenakshi shukla at 2012-09-15 05:09:49

9. Thanks, I understand the add function better now (
View Tutorial          By: Venus at 2011-02-11 09:09:55

10. Error loading SolarisSerial: java.lang.Unsatisfied
View Tutorial          By: Rahul at 2008-09-09 04:05:35