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 spec) throws MalformedURLException 

Source Link

Document

Creates a URL object from the String representation.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL url = new URL("jar:file:/c://my.jar!/");
    JarURLConnection conn = (JarURLConnection) url.openConnection();

    Manifest manifest = conn.getManifest();
    System.out.println(manifest);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL url = new URL("jar:file:/c://my.jar!/");
    JarURLConnection conn = (JarURLConnection) url.openConnection();

    JarEntry jarEntry = conn.getJarEntry();
    System.out.println(jarEntry.getName());
}

From source file:MainClass.java

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

    URL u = new URL("http://www.java2s.com");
    HttpURLConnection http = (HttpURLConnection) u.openConnection();
    http.setRequestMethod("HEAD");
    System.out.println(u + "was last modified at " + new Date(http.getLastModified()));
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.google.com");
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();

    long date = httpCon.getDate();
    if (date == 0)
        System.out.println("No date information.");
    else//from w  w w .j a va2  s. co  m
        System.out.println("Date: " + new Date(date));

}

From source file:lycos.java

public static void main(String[] args) {

    try {/*from w  w  w.jav  a2  s.co m*/
        String thisLine;
        URL u = new URL("http://www.google.com");
        DataInputStream theHTML = new DataInputStream(u.openStream());
        while ((thisLine = theHTML.readLine()) != null) {
            System.out.println(thisLine);
        } // while loop ends here
    } catch (MalformedURLException e) {
        System.err.println(e);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.google.com");
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();

    long date = httpCon.getLastModified();
    if (date == 0)
        System.out.println("No last-modified information.");
    else/*from w  w  w. j  a v  a 2 s. c o m*/
        System.out.println("Last-Modified: " + new Date(date));

}

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.google.com");
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();

    long date = httpCon.getExpiration();
    if (date == 0)
        System.out.println("No expiration information.");
    else/*  w  w  w  . j av  a2s  .  c o  m*/
        System.out.println("Expires: " + new Date(date));

}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    uc.connect();/*w  w  w  .  j a  v a2  s .co  m*/
    System.out.println("Content-type: " + uc.getContentType());
    System.out.println("Content-encoding: " + uc.getContentEncoding());
    System.out.println("Date: " + new Date(uc.getDate()));
    System.out.println("Last modified: " + new Date(uc.getLastModified()));
    System.out.println("Expiration date: " + new Date(uc.getExpiration()));
    System.out.println("Content-length: " + uc.getContentLength());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL url = new URL("jar:file:/c://my.jar!/");
    JarURLConnection conn = (JarURLConnection) url.openConnection();

    Attributes attrs = conn.getMainAttributes();
    System.out.println(attrs.isEmpty());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL url = new URL("jar:file:/c://my.jar!/");
    JarURLConnection conn = (JarURLConnection) url.openConnection();

    Attributes attrs = conn.getAttributes();

}