Example usage for java.net URL URL

List of usage examples for java.net URL URL

Introduction

In this page you can find the example usage for java.net URL URL.

Prototype

public URL(String protocol, String host, int port, String file) throws MalformedURLException 

Source Link

Document

Creates a URL object from the specified protocol , host , port number, and file .

host can be expressed as a host name or a literal IP address.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    URL url = new URL("http", "hostname", 80, "index.html");

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    URL url = new URL("http", "hostname", 80, "index.html");

    System.out.println(url);//from w  w  w.  j  av a  2s  .c om
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    int c;/*from  w w w  .  j  ava 2  s  . com*/
    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());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    int c;/* ww  w. j a v  a  2 s .  c  o m*/
    URL hp = new URL("http", "www.java2s.com", 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");
    }
}