java.lang.Object | |
↳ | java.net.URL |
A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC 1738.
http://username:password@host:8080/directory/file?query#ref
:
Component | Example value | Also known as |
---|---|---|
Protocol | http | scheme |
Authority | username:password@host:8080 | |
User Info | username:password | |
Host | host | |
Port | 8080 | |
File | /directory/file?query | |
Path | /directory/file | |
Query | query | |
Ref | ref | fragment |
Jar files
from the
filesystemMalformedURLException
. Applications may install handlers for other
schemes using setURLStreamHandlerFactory(URLStreamHandlerFactory)
or with the java.protocol.handler.pkgs
system property.
The URI
class can be used to manipulate URLs of any protocol.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new URL instance by parsing
spec .
| |||||||||||
Creates a new URL by resolving
spec relative to context .
| |||||||||||
Creates a new URL by resolving
spec relative to context .
| |||||||||||
Creates a new URL of the given component parts.
| |||||||||||
Creates a new URL of the given component parts.
| |||||||||||
Creates a new URL of the given component parts.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns true if this URL equals
o .
| |||||||||||
Returns the authority part of this URL, or null if this URL has no
authority.
| |||||||||||
Equivalent to
openConnection().getContent(types) .
| |||||||||||
Returns the content of the resource which is referred by this URL.
| |||||||||||
Returns the default port number of the protocol used by this URL.
| |||||||||||
Returns the file of this URL.
| |||||||||||
Returns the host name or IP address of this URL.
| |||||||||||
Returns the path part of this URL.
| |||||||||||
Returns the port number of this URL or
-1 if this URL has no
explicit port.
| |||||||||||
Returns the protocol of this URL like "http" or "file".
| |||||||||||
Returns the query part of this URL, or null if this URL has no query.
| |||||||||||
Returns the value of the reference part of this URL, or null if this URL
has no reference part.
| |||||||||||
Returns the user info of this URL, or null if this URL has no user info.
| |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Returns a new connection to the resource referred to by this URL.
| |||||||||||
Returns a new connection to the resource referred to by this URL.
| |||||||||||
Equivalent to
openConnection().getInputStream(types) .
| |||||||||||
Returns true if this URL refers to the same resource as
otherURL .
| |||||||||||
Sets the stream handler factory for this VM.
| |||||||||||
Returns a string containing a concise, human-readable representation of
this URL.
| |||||||||||
Returns a string containing a concise, human-readable representation of
this URL.
| |||||||||||
Returns the URI equivalent to this URL.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Sets the properties of this URL using the provided arguments.
| |||||||||||
Sets the properties of this URL using the provided arguments.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates a new URL instance by parsing spec
.
MalformedURLException | if spec could not be parsed as a
URL.
|
---|
Creates a new URL by resolving spec
relative to context
.
context | the URL to which spec is relative, or null for
no context in which case spec must be an absolute URL. |
---|
MalformedURLException | if spec could not be parsed as a
URL or has an unsupported protocol.
|
---|
Creates a new URL by resolving spec
relative to context
.
context | the URL to which spec is relative, or null for
no context in which case spec must be an absolute URL. |
---|---|
handler | the stream handler for this URL, or null for the protocol's default stream handler. |
MalformedURLException | if the given string spec could not
be parsed as a URL or an invalid protocol has been found.
|
---|
Creates a new URL of the given component parts. The URL uses the protocol's default port.
MalformedURLException | if the combination of all arguments do not represent a valid URL or if the protocol is invalid. |
---|
Creates a new URL of the given component parts. The URL uses the protocol's default port.
host | the host name or IP address of the new URL. |
---|---|
port | the port, or -1 for the protocol's default port. |
file | the name of the resource. |
MalformedURLException | if the combination of all arguments do not represent a valid URL or if the protocol is invalid. |
---|
Creates a new URL of the given component parts. The URL uses the protocol's default port.
host | the host name or IP address of the new URL. |
---|---|
port | the port, or -1 for the protocol's default port. |
file | the name of the resource. |
handler | the stream handler for this URL, or null for the protocol's default stream handler. |
MalformedURLException | if the combination of all arguments do not represent a valid URL or if the protocol is invalid. |
---|
Returns true if this URL equals o
. URLs are equal if they have
the same protocol, host, port, file, and reference.
Some implementations of URL.equals() resolve host names over the network. This is problematic:
Map
and Set
expect that equals
and hashCode
will return quickly.
By violating this assumption, this method posed potential performance
problems.
This problem is fixed in Android 4.0 (Ice Cream Sandwich). In that release, URLs are only equal if their host names are equal (ignoring case).
o | the object to compare this instance with. |
---|
true
if the specified object is equal to this Object
; false
otherwise.Returns the authority part of this URL, or null if this URL has no authority.
Equivalent to openConnection().getContent(types)
.
IOException |
---|
Returns the content of the resource which is referred by this URL. By
default this returns an InputStream
, or null if the content type
of the response is unknown.
IOException |
---|
Returns the default port number of the protocol used by this URL. If no
default port is defined by the protocol or the URLStreamHandler
,
-1
will be returned.
Returns the port number of this URL or -1
if this URL has no
explicit port.
If this URL has no explicit port, connections opened using this URL
will use its default port
.
Returns the protocol of this URL like "http" or "file". This is also known as the scheme. The returned string is lower case.
Returns the query part of this URL, or null if this URL has no query.
Returns the value of the reference part of this URL, or null if this URL has no reference part. This is also known as the fragment.
Returns the user info of this URL, or null if this URL has no user info.
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
Returns a new connection to the resource referred to by this URL.
proxy | the proxy through which the connection will be established. |
---|
IOException | if an I/O error occurs while opening the connection. |
---|---|
IllegalArgumentException | if the argument proxy is null or of is an invalid type. |
UnsupportedOperationException | if the protocol handler does not support opening connections through proxies. |
Returns a new connection to the resource referred to by this URL.
IOException | if an error occurs while opening the connection. |
---|
Equivalent to openConnection().getInputStream(types)
.
IOException |
---|
Returns true if this URL refers to the same resource as otherURL
.
All URL components except the reference field are compared.
Sets the stream handler factory for this VM.
Error | if a URLStreamHandlerFactory has already been installed for the current VM. |
---|
Returns a string containing a concise, human-readable representation of this URL.
Returns a string containing a concise, human-readable representation of
this URL. The returned string is the same as the result of the method
toExternalForm()
.
Returns the URI equivalent to this URL.
URISyntaxException | if this URL cannot be converted into a URI. |
---|
Sets the properties of this URL using the provided arguments. Only a
URLStreamHandler
can use this method to set fields of the
existing URL instance. A URL is generally constant.
Sets the properties of this URL using the provided arguments. Only a
URLStreamHandler
can use this method to set fields of the
existing URL instance. A URL is generally constant.