Java Reference
In-Depth Information
tedEncodingException
{
String encodedData = URLEncoder.encode("the string
ü@foo-bar", "utf-8");
System.out.println(encodedData);
System.out.println(URLDecoder.decode(encodedData,
"utf-8"));
}
}
Note
You might want to check out Wikipedia's “Percent-encoding” topic (
ht-
tp://en.wikipedia.org/wiki/Percent-encoding
)
to learn more about
URL encoding (and the more accurate percent-encoding term).
URI
The
URI
class represents URIs (e.g., URNs and URLs). It doesn't provide access to a
resource when the URI is a URL.
A
URI
instancestoresacharacterstringthatconformstothefollowingsyntaxatthe
highest level:
[
scheme
:]
scheme-specific-part
[#
fragment
]
ThissyntaxrevealsthateveryURIoptionally beginswitha
scheme
followedbya
coloncharacter,wherea
scheme
canbethoughtofasanapplication-level protocolfor
obtaininganInternetresource.However,thisdefinitionistoonarrowbecauseitimplies
thattheURIisalwaysaURL.Aschemecanhavenothingtodowithresourcelocation.
For example, urn is the scheme for identifying URNs.
A scheme is followed by a
scheme-specific-part
that provides an instance
tor.ca
isaninstanceofthehttpscheme.Scheme-specific-partsconformtotheallow-
ablesyntaxoftheirschemesandtotheoverallsyntaxstructureofaURI(includingwhat
characters can be specified literally and what characters must be encoded).
Aschemeconcludeswithanoptional
#
-prefixed
fragment
,whichisashortstring
of characters that refers to a resource subordinate to another primary resource. The
primary resource is identified by a URI; the fragment points to the subordinate re-
source. For example,
http://tutortutor.ca/document.txt#line=5,10