Java API Tutorial - Java URL.toExternalForm()








Syntax

URL.toExternalForm() has the following syntax.

public String toExternalForm()

Example

In the following code shows how to use URL.toExternalForm() method.

import java.net.URL;
//from w w w  .  j  a  va  2 s  .c  om
public class Main {
  public static void main(String[] argv) throws Exception {
    URL relativeURL, baseURL;
    baseURL = new URL("http://www.java2s.com/abc/d.htm");
    relativeURL = new URL(baseURL, "../a.htm");
    System.out.println(relativeURL.toExternalForm());

  }
}

The code above generates the following result.