Creates a URL object from the specified
protocol, host, port
number, and file.
host can be expressed as a host name or a literal
IP address. If IPv6 literal address is used, it should be
enclosed in square brackets ('[' and ']'), as
specified by RFC 2732;
However, the literal IPv6 address format defined in RFC 2373: IP
Version 6 Addressing Architecture is also accepted.
Specifying a port number of -1
indicates that the URL should use the default port for the
protocol.
If this is the first URL object being created with the specified
protocol, a stream protocol handler object, an instance of
class URLStreamHandler, is created for that protocol:
URLStreamHandlerFactory as the stream handler factory,
then the createURLStreamHandler method of that instance
is called with the protocol string as an argument to create the
stream protocol handler.
URLStreamHandlerFactory has yet been set up,
or if the factory's createURLStreamHandler method
returns null, then the constructor finds the
value of the system property:
java.protocol.handler.pkgs
If the value of that system property is not null,
it is interpreted as a list of packages separated by a vertical
slash character '|'. The constructor tries to load
the class named:
<package>.<protocol>.Handler
where <package> is replaced by the name of the package
and <protocol> is replaced by the name of the protocol.
If this class does not exist, or if the class exists but it is not
a subclass of URLStreamHandler, then the next package
in the list is tried.
<system default package>.<protocol>.Handler
If this class does not exist, or if the class exists but it is not a
subclass of URLStreamHandler, then a
MalformedURLException is thrown.
Protocol handlers for the following protocols are guaranteed to exist on the search path :-
http, https, ftp, file, and jar
Protocol handlers for additional protocols may also be
available.
No validation of the inputs is performed by this constructor.
protocol | the name of the protocol to use. | |
host | the name of the host. | |
port | the port number on the host. | |
file | the file on the host |
MalformedURLException | if an unknown protocol is specified. |
java.lang.System.getProperty(java.lang.String), java.net.URL.setURLStreamHandlerFactory(
java.net.URLStreamHandlerFactory), java.net.URLStreamHandler, java.net.URLStreamHandlerFactory.createURLStreamHandler(
java.lang.String)
Diagram: URL