Java Reference
In-Depth Information
URI
declares various getter methods that let you retrieve
URI
components. For
example,
String getScheme()
lets you retrieve the scheme, and
String
getFragment()
returns a URL-decoded fragment. This class also declares
boolean isAbsolute()
and
boolean isOpaque()
methodsthatreturntrue
when a URI is absolute and opaque.
Listing9-10
presentsanapplicationthatletsyoulearnaboutURIcomponentsalong
with absolute and opaque URIs.
Listing 9-10.
Learning about a URI
import java.net.URI;
import java.net.URISyntaxException;
class URIComponents
{
public static void main(String[] args) throws URISyn-
taxException
{
if (args.length != 1)
{
System.err.println("usage:
java
uricomponents
uri");
return;
}
URI uri = new URI(args[0]);
System.out.println("authority
=
"+uri.getAuthority());
System.out.println("fragment = "+uri.getFragment());
System.out.println("host = "+uri.getHost());
System.out.println("path = "+uri.getPath());
System.out.println("port = "+uri.getPort());
System.out.println("query = "+uri.getQuery());
System.out.println("scheme = "+uri.getScheme());
System.out.println("scheme-specific
part
=
"+uri.getSchemeSpecificPart());
System.out.println("user
info
=