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;
/*w  ww .j a v  a 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.





















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder