Example usage for java.net URL openConnection

List of usage examples for java.net URL openConnection

Introduction

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

Prototype

public URLConnection openConnection() throws java.io.IOException 

Source Link

Document

Returns a java.net.URLConnection URLConnection instance that represents a connection to the remote object referred to by the URL .

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();

    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();

    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: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();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);/*from w  w  w .  j a  va  2  s  . c o  m*/
    OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());

    writer.write("value=1&anotherValue=1");
    writer.flush();
    String line;
    BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    while ((line = reader.readLine()) != null) {
        System.out.println(line);
    }
    writer.close();
    reader.close();

}

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();

    conn = (JarURLConnection) url.openConnection();
    JarFile jarfile = conn.getJarFile();
}

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();

    System.out.println("Response code is " + httpCon.getResponseCode());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    int c;//from   www  .  j  a v  a 2s. 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: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();
    Certificate[] certs = conn.getCertificates();

}