Java by API/javax.net/URLConnection
Содержание
URLConnection: getContentLength()
<source lang="java">
/*
* 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()); }
}
</source>
URLConnection: getContentType()
<source lang="java">
/*
* 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()); }
}
</source>
URLConnection: getDate()
<source lang="java">
/*
* 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()); }
}
</source>
URLConnection: getExpiration()
<source lang="java">
/*
* 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()); }
}
</source>
URLConnection: getInputStream()
<source lang="java">
/*
* 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"); } }
}
</source>
URLConnection: getLastModified()
<source lang="java">
/*
* 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()); }
}
</source>