A Sample Class That Demonstrates the Use of the java.net.URL Class - Java Network

Java examples for Network:URL

Description

A Sample Class That Demonstrates the Use of the java.net.URL Class

Demo Code

import java.net.URL;

public class Main {
  public static void main(String[] args) {
    String baseURLStr = "http://www.ietf.org/rfc/rfc3986.txt";
    String relativeURLStr = "rfc2732.txt";
    try {/*www  .  j  ava 2s. c o  m*/
      URL baseURL = new URL (baseURLStr);
      URL resolvedRelativeURL = new URL(baseURL, relativeURLStr);
      System.out.println("Base URL:" + baseURL);
      System.out.println("Relative URL String:" +
                         relativeURLStr);
      System.out.println("Resolved Relative URL:" +
                         resolvedRelativeURL);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Result


Related Tutorials