URL: openConnection() : URL « javax.net « Java by API






URL: openConnection()

/*
 * 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.java2s.com", 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());
  }
}
           
       








Related examples in the same category

1.new URL(String address)
2.new URL(String protocol, String host, int port, String file)
3.URL: getFile()
4.URL: getHost()
5.URL: getProtocol()
6.URL: getPort()
7.URL: toExternalForm()