URI Resolution

In this chapter you will learn:

  1. How to do URI Resolution

Resolution

Resolution is the process of resolving one URI against another URI.

The resulting URI is constructed from components of both URIs. Check http://tools.ietf.org/html/rfc2396 for the details.

Resolution of both absolute and relative URIs, and of both absolute and relative paths in the case of hierarchical URIs, is supported.

URI declares

URI resolve(String str)

and

URI resolve(URI uri)

methods for resolving the original URI argument against the base URI contained in the current URI object.

import java.net.URI;
import java.net.URISyntaxException;
//from   j  a  v  a  2  s. co m
public class Main {
  public static void main(String[] args) throws URISyntaxException {
    URI uri = new URI("http://java2s.com/");
    System.out.println("Resolved URI = " + uri.resolve("/index.htm"));
  }
}

Output:

Next chapter...

What you will learn in the next chapter:

  1. How to do URI Relativization
Home » Java Tutorial » URL URI
URL
URL Creation
URL for jar file
URL Components
Convert file path to URL
URL Relative
URL Protocol
Read from URL
Compare URL
URLConnection
HTTP Header
URLConnection Post
Cookie
URLConnection Read
HttpURLConnection
HttpURLConnection Properties
HttpURLConnection proxy
HttpURLConnection Authenticator
HTTPS
JarURLConnection
Encode a URL
Decode a URL
URI
URI Normalization
URI Resolution
URI Relativization
Convert URI to URL
IP Address
IP Ping
NetworkInterface