Creating a URL - Java Network

Java examples for Network:URL

Description

Creating a URL

Demo Code

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
  public static void main(String[] args) throws Exception {
    try {/*from  www. ja  va2  s  .  c  o  m*/
      // With components.
      URL url = new URL("http", "hostname", 80, "index.html");

      // With a single string.
      url = new URL("http://hostname:80/index.html");
    } catch (MalformedURLException e) {
    }
  }
}

Related Tutorials