Java Reference
In-Depth Information
• Otherwise,anewrelativehierarchicalURIisconstructedwithqueryandfrag-
ment components taken from the argument URI, and with a path component
computed by removing this URI's path from the beginning of the argument
URI's path.
Listing 9-13 presents an application that lets you experiment with relativize() .
Listing 9-13. Relativizing URIs
import java.net.URI;
import java.net.URISyntaxException;
class Relativize
{
public static void main(String[] args) throws URISyn-
taxException
{
if (args.length != 2)
{
System.err.println("usage: java relativize uri1
uri2");
return;
}
URI uri1 = new URI(args[0]);
URI uri2 = new URI(args[1]);
System.out.println("relativized
uri
=
"+ur-
i1.relativize(uri2));
}
}
Compile Listing9-13 ( javac Relativize.java )andruntheapplicationasfol-
lows: java Relativize http://java.sun.com/j2se/1.3/
http://java.sun.com/j2se/1.3/docs/guide/collections/
designfaq.html#28 . You should observe the following output:
Relativized URI = docs/guide/collections/designfaq.html#28
Search WWH ::




Custom Search