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. it's very nice answer
View Tutorial          By: ahmedmohsen at 2011-12-31 19:26:09

2. it's cool
View Tutorial          By: RInam Shah at 2011-06-20 02:48:20

3. you really dont know how much i want to thank u...
View Tutorial          By: Angana Sengupta at 2013-01-23 18:34:51

4. Best Example sir
View Tutorial          By: Hiren Dangar at 2015-04-23 06:55:26

5. for ex

public class test()
{

View Tutorial          By: Anundhara at 2012-08-11 06:54:57

6. extremely good
View Tutorial          By: rahul at 2011-06-09 05:59:43

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

8. simple examples that i can understand ,.,,by the w
View Tutorial          By: Chriskuang at 2015-03-19 03:05:59

9. informative article.......
View Tutorial          By: Nithin at 2012-08-17 15:32:37

10. Please, I need help, how can i write a program &qu
View Tutorial          By: LULU at 2012-11-23 01:34:07