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. #include<iostream>
#include<conio.

View Tutorial          By: Zohaib Farooq at 2011-05-23 12:47:54

2. java.lang.IllegalArgumentException means usually t
View Tutorial          By: Seink at 2008-11-12 11:03:00

3. we can write an abstract class without any abstrac
View Tutorial          By: keerthi at 2013-08-20 16:31:38

4. Very good.
But is this (Accessor functions

View Tutorial          By: peter at 2011-07-20 13:13:44

5. Thanks a lot for this great post.
View Tutorial          By: Ram Para at 2012-03-23 17:07:09

6. hi plz help
how do we change project develo

View Tutorial          By: pratik jogwar at 2012-06-07 19:58:47

7. my code is unable to open included files
ho

View Tutorial          By: MANAS at 2013-09-08 05:44:46

8. this tutorial example of inheritence is taken from
View Tutorial          By: vinod kumar gaur at 2011-07-17 23:18:00

9. I got the solution people. just do the following a
View Tutorial          By: Nicholas Ndegwa at 2011-05-03 03:05:03

10. excellent..... thanks it help me a lot.......
View Tutorial          By: REJAPUTRA at 2009-10-23 09:19:25