URI uri =new URI("http://myname@www.baidu.com:8888/path1/path1?query1=value1#fffffff");
System.out.println("URI.getAuthority() = "+uri.getAuthority());
System.out.println("URI.getFragment() = "+uri.getFragment());
System.out.println("URI.getHost() = "+uri.getHost());
System.out.println("URI.getPath() = "+uri.getPath());
System.out.println("URI.getPort() = "+uri.getPort());
System.out.println("URI.getQuery() = "+uri.getQuery());
System.out.println("URI.getRawAuthority() = "+uri.getRawAuthority());
System.out.println("URI.getRawFragment() = "+uri.getRawFragment());
System.out.println("URI.getRawPath() = "+uri.getRawPath());
System.out.println("URI.getRawQuery() = "+uri.getRawQuery());
System.out.println("URI.getRawSchemeSpecificPart() = "+uri.getRawSchemeSpecificPart());
System.out.println("URI.getUserInfo() = "+uri.getUserInfo());
System.out.println("URI.getSchemeSpecificPart() = "+uri.getSchemeSpecificPart());
URL url=uri.toURL();
System.out.println("URL.getAuthority() = "+url.getAuthority());
System.out.println("URL.getDefaultPort() = "+url.getDefaultPort());
System.out.println("URL.getFile() = "+url.getFile());
System.out.println("URL.getHost() = "+url.getHost());
System.out.println("URL.getPath() = "+url.getPath());
System.out.println("URL.getPort() = "+url.getPort());
System.out.println("URL.getProtocol() = "+url.getProtocol());
System.out.println("URL.getQuery() = "+url.getQuery());
System.out.println("URL.getRef() = "+url.getRef());
System.out.println("URL.getUserInfo() = "+url.getUserInfo());
输出:
URI.getAuthority() = myname@www.baidu.com:8888
URI.getFragment() = fffffff
URI.getHost() = www.baidu.com
URI.getPath() = /path1/path1
URI.getPort() = 8888
URI.getQuery() = query1=value1
URI.getRawAuthority() = myname@www.baidu.com:8888
URI.getRawFragment() = fffffff
URI.getRawPath() = /path1/path1
URI.getRawQuery() = query1=value1
URI.getRawSchemeSpecificPart() = //myname@www.baidu.com:8888/path1/path1?query1=value1
URI.getUserInfo() = myname
URI.getSchemeSpecificPart() = //myname@www.baidu.com:8888/path1/path1?query1=value1
URL.getAuthority() = myname@www.baidu.com:8888
URL.getDefaultPort() = 80
URL.getFile() = /path1/path1?query1=value1
URL.getHost() = www.baidu.com
URL.getPath() = /path1/path1
URL.getPort() = 8888
URL.getProtocol() = http
URL.getQuery() = query1=value1
URL.getRef() = fffffff
URL.getUserInfo() = myname