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 myURL = new URL("http://www.google.com");
    BufferedReader so = new BufferedReader(new InputStreamReader(myURL.openStream()));
    while (true) {
        String output = so.readLine();
        if (output != null) {
            System.out.println(output);
        } else {// w  w  w .  ja  v  a2 s. c  o m
            break;
        }
    }
    so.close();
}

From source file:Main.java

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

    URL google = new URL("http://www.google.com/");
    URLConnection googleConnection = google.openConnection();
    DataInputStream dis = new DataInputStream(googleConnection.getInputStream());
    StringBuffer inputLine = new StringBuffer();
    String tmp;//from ww w  .j a v  a2s . c o  m
    while ((tmp = dis.readLine()) != null) {
        inputLine.append(tmp);
        System.out.println(tmp);
    }
    // use inputLine.toString(); here it would have whole source
    dis.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    final ImageIcon icon = new ImageIcon(new URL("http://www.java2s.com/style/download.png"));
    JOptionPane.showMessageDialog(null, "Blah blah blah", "About", JOptionPane.INFORMATION_MESSAGE, icon);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL source = new URL("http://www.a.com");
    URL mirror = new URL("http://www.b.com");
    byte[] sourceDigest = getDigestFromURL(source);
    byte[] mirrorDigest = getDigestFromURL(mirror);
    if (MessageDigest.isEqual(sourceDigest, mirrorDigest)) {
        System.out.println(mirror + " is up to date");
    } else {//from  w  w  w . j a  v a  2s  .  c o m
        System.out.println(mirror + " needs to be updated");
    }
}

From source file:Main.java

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

    BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream());

    int byteRead;
    while ((byteRead = buffer.read()) != -1) {
        System.out.println((char) byteRead);
    }/*from   w ww. j  ava 2 s .  com*/
    buffer.close();
}

From source file:MainClass.java

public static void main(String args[]) {
    try {/*from w w w  . j ava2  s .c o  m*/

        URL url = new URL("http://www.java2s.com");

        // Obtain output stream
        InputStream is = url.openStream();

        // Read and display data from url
        byte buffer[] = new byte[1024];
        int i;
        while ((i = is.read(buffer)) != -1) {
            System.out.write(buffer, 0, i);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

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

    InputStream in = null;/*from ww w .  ja  v a2  s.  c  o  m*/
    try {
        URL u = new URL("http://www.java2s.com");
        in = u.openStream();
        for (int c = in.read(); c != -1; c = in.read()) {
            System.out.write(c);
        }
        in.close();
    } catch (MalformedURLException ex) {
        System.err.println("not a URL Java understands.");
    } finally {
        if (in != null)
            in.close();
    }
}

From source file:Main.java

public static void main(final String args[]) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    BufferedImage image = ImageIO.read(url);

    for (int x = 0; x < image.getWidth(); x++) {
        for (int y = 0; y < image.getHeight(); y++) {
            int clr = image.getRGB(x, y);
            int red = (clr & 0x00ff0000) >> 16;
            int green = (clr & 0x0000ff00) >> 8;
            int blue = clr & 0x000000ff;

            System.out.println("Red Color value = " + red);
            System.out.println("Green Color value = " + green);
            System.out.println("Blue Color value = " + blue);
        }/*from   w w w. j  av  a2s  . c o m*/
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    SplashScreen splash = SplashScreen.getSplashScreen();
    splash.setImageURL(new URL("http://yourURL"));
    System.out.println(splash.getImageURL());
}

From source file:Main.java

static public void main(String args[]) throws Exception {
    URL myurl[] = { new URL("file:///C:/CH3/ClassLoader/web/"), new URL("http://www.java2s.edu/~xyx/test/") };
    URLClassLoader x = new URLClassLoader(myurl);
    Class c = x.loadClass("TestURL");

    Class getArg1[] = { (new String[1]).getClass() };
    Method m = c.getMethod("main", getArg1);
    String[] my1 = { "arg1 passed", "arg2 passed" };
    Object myarg1[] = { my1 };/*w  w w  .j a  v a2s.  c om*/
    m.invoke(null, myarg1);

    Object ob = c.newInstance();
    Class arg2[] = {};
    Method m2 = c.getMethod("tt", arg2);
    m2.invoke(ob, null);

    Class arg3[] = { (new String()).getClass(), int.class };
    Method m3 = c.getMethod("tt", arg3);
    Object myarg2[] = { "Arg1", new Integer(100) };
    m3.invoke(ob, myarg2);
}