提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
如何在Java程序中使用URI类。
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() +