Java by API/javax.net/URLConnection — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Содержание
URLConnection: getContentLength()
/*
* Output:
*
Date: 1145919603000
Type: text/html
Exp: 0
Last M: 1143834458000
Length: 208546
*/
import java.net.URL;
import java.net.URLConnection;
public class MainClass {
public static void main(String args[]) throws Exception {
int c;
URL hp = new URL("http", "www.jexp.ru", 80, "/");
URLConnection hpCon = hp.openConnection();
System.out.println("Date: " + hpCon.getDate());
System.out.println("Type: " + hpCon.getContentType());
System.out.println("Exp: " + hpCon.getExpiration());
System.out.println("Last M: " + hpCon.getLastModified());
System.out.println("Length: " + hpCon.getContentLength());
}
}
URLConnection: getContentType()
/*
* Output:
*
Date: 1145919603000
Type: text/html
Exp: 0
Last M: 1143834458000
Length: 208546
*/
import java.net.URL;
import java.net.URLConnection;
public class MainClass {
public static void main(String args[]) throws Exception {
int c;
URL hp = new URL("http", "www.jexp.ru", 80, "/");
URLConnection hpCon = hp.openConnection();
System.out.println("Date: " + hpCon.getDate());
System.out.println("Type: " + hpCon.getContentType());
System.out.println("Exp: " + hpCon.getExpiration());
System.out.println("Last M: " + hpCon.getLastModified());
System.out.println("Length: " + hpCon.getContentLength());
}
}
URLConnection: getDate()
/*
* Output:
*
Date: 1145919603000
Type: text/html
Exp: 0
Last M: 1143834458000
Length: 208546
*/
import java.net.URL;
import java.net.URLConnection;
public class MainClass {
public static void main(String args[]) throws Exception {
int c;
URL hp = new URL("http", "www.jexp.ru", 80, "/");
URLConnection hpCon = hp.openConnection();
System.out.println("Date: " + hpCon.getDate());
System.out.println("Type: " + hpCon.getContentType());
System.out.println("Exp: " + hpCon.getExpiration());
System.out.println("Last M: " + hpCon.getLastModified());
System.out.println("Length: " + hpCon.getContentLength());
}
}
URLConnection: getExpiration()
/*
* Output:
*
Date: 1145919603000
Type: text/html
Exp: 0
Last M: 1143834458000
Length: 208546
*/
import java.net.URL;
import java.net.URLConnection;
public class MainClass {
public static void main(String args[]) throws Exception {
int c;
URL hp = new URL("http", "www.jexp.ru", 80, "/");
URLConnection hpCon = hp.openConnection();
System.out.println("Date: " + hpCon.getDate());
System.out.println("Type: " + hpCon.getContentType());
System.out.println("Exp: " + hpCon.getExpiration());
System.out.println("Last M: " + hpCon.getLastModified());
System.out.println("Length: " + hpCon.getContentLength());
}
}
URLConnection: getInputStream()
/*
* Output:
*
<HTML>
<HEAD>
<title> Java examples (example source code) Organized by topic </title>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"> <meta name="author" content="Demo Source and Support Ltd."/>
<meta name="copyright" content="?2003 Demo Source and Support Ltd."/>
<meta name="description" CONTENT=" Java examples (example source code) Organized by topic " />
<meta name="keywords" CONTENT=" Java examples (example source code) Organized by topic "/>
<meta http-equiv="content-style-type" content="text/css"/>
<LINK href="http://www.jexp.ru/style/jss.css" type=text/css rel=stylesheet>
<SCRIPT language=javascript1.2>
...
...
*/
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class MainClass {
public static void main(String args[]) throws Exception {
int c;
URL hp = new URL("http", "www.jexp.ru", 80, "/");
URLConnection hpCon = hp.openConnection();
if (hpCon.getContentLength() > 0) {
InputStream input = hpCon.getInputStream();
int i = hpCon.getContentLength();
while (((c = input.read()) != -1) && (--i > 0)) {
System.out.print((char) c);
}
input.close();
} else {
System.out.println("No Content Available");
}
}
}
URLConnection: getLastModified()
/*
* Output:
*
Date: 1145919603000
Type: text/html
Exp: 0
Last M: 1143834458000
Length: 208546
*/
import java.net.URL;
import java.net.URLConnection;
public class MainClass {
public static void main(String args[]) throws Exception {
int c;
URL hp = new URL("http", "www.jexp.ru", 80, "/");
URLConnection hpCon = hp.openConnection();
System.out.println("Date: " + hpCon.getDate());
System.out.println("Type: " + hpCon.getContentType());
System.out.println("Exp: " + hpCon.getExpiration());
System.out.println("Last M: " + hpCon.getLastModified());
System.out.println("Length: " + hpCon.getContentLength());
}
}