import java.net.URI;
import java.net.URISyntaxException;
public class Main {
/**
* 时 代 J a v a 公 众 号 提 供
**/
public static void main(String[] args) {
String baseURIStr = "http://nowjava.com/fake.html?" +
"id=999&rate=1.5%25#foo";
String relativeURIStr = "../folder/welcome.html";
try {
URI baseURI = new URI(baseURIStr);
URI relativeURI = new URI(relativeURIStr);
// Resolve the relative URI with respect to the base URI
URI resolvedURI = baseURI.resolve(relativeURI);
printURIDetails(baseURI);
printURIDetails(relativeURI);
printURIDetails(resolvedURI);//nowjava.com - 时 代 Java
}
catch (URISyntaxException e) {
e.printStackTrace();
}
}
public static void printURIDetails(URI uri) {
System.out.println("URI:" + uri);
System.out.println("Normalized:" + uri.normalize());
String parts = "[Scheme=" + uri.getScheme() +
", Authority=" + uri.getAuthority() +
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。