U3.java
import java.net.*;
/**
Demonstrate conversion between relative and absolute URIs.
*/
public class U3
{
public static void main(String argv[])
{
String basestring = "http://www.xyz.com";
String querystring =
"http://www.xyz.com/cgi-bin/bozo.pl?x=7&y=3";
String relstring = "/cgi-bin/bimbo.py?pi=3.14159";
try {
URI base = new URI(basestring);
URI query = new URI(querystring);
URI rel = new URI(relstring);
System.out.println(" Base URI = " + base);
System.out.println(" Query URI = " + query);
URI relative = base.relativize(query);
System.out.println("Relativized URI = " + relative);
System.out.println(" Relative URI = " + rel);
URI combined = base.resolve(rel);
System.out.println(" Combined URI = " + combined);
}
catch (URISyntaxException e) {
e.printStackTrace();
}
}
}