URI Relativization
In this chapter you will learn:
Relativization
Relativization is the inverse of resolution.
URI declares a URI relativize(URI uri) method for relativizing its uri argument against the URI in the current URI object.
For any two normalized URI instancesu
and v
,
u.relativize(u.resolve(v)).equals(v)
and
u.resolve(u.relativize(v)).equals(v)
evaluate to true
.
relativize()
performs relativization of its URI
argument's URI against the URI in the URI object on
which this method was called as follows:
import java.net.URI;
import java.net.URISyntaxException;
/* j av a2 s . c om*/
public class Main {
public static void main(String[] args) throws URISyntaxException {
URI uri1 = new URI("http://java2s.com/");
URI uri2 = new URI("http://java2s.com/index.htm");
System.out.println("Relativized URI = " + uri1.relativize(uri2));
}
}
Output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » URL URI