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 args[]) throws Exception {
    URL u = new URL("http://www.yourserver.com:80/abc/demo.htm");
    System.out.println("The URL is " + u);
    System.out.println("The file part is " + u.getFile());
    u.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.1.1.10", 10)));

}

From source file:Main.java

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

    InputStream s = httpCon.getInputStream();

}

From source file:Main.java

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

    URLConnection.setDefaultAllowUserInteraction(true);

}

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();
    JarFile jarfile = conn.getJarFile();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.x.com");
    URLConnection urlc = url.openConnection();
    urlc.setRequestProperty("User-Agent", "Mozilla 5.0 (Windows; U; " + "Windows NT 5.1; en-US; rv:1.8.0.11) ");

    InputStream is = urlc.getInputStream();
    int c;/*  w w w  .  j  av  a2  s .  co  m*/
    while ((c = is.read()) != -1)
        System.out.print((char) c);
}

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

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

    JarFile jarFile = conn.getJarFile();
    System.out.println(jarFile);/*  w  ww .  j av  a 2s.  c o m*/
}

From source file:Main.java

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

    String thisLine;//  w  w w .j  a  v  a  2  s .c o m
    URL u = new URL("http://www.google.com");
    DataInputStream theHTML = new DataInputStream(u.openStream());
    while ((thisLine = theHTML.readLine()) != null) {
        System.out.println(thisLine);
    }

}

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