GeezerVison is showing docs.oracle.com — URL (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.net
Class URL
-
-
Constructor Summary
Constructors
| Constructor |
Description |
URL(String spec) |
Creates a URL object from the String
representation.
|
URL(String protocol,
String host,
int port,
String file) |
Creates a URL object from the specified
protocol, host, port
number, and file.
|
URL(String protocol,
String host,
int port,
String file,
URLStreamHandler handler) |
Creates a URL object from the specified
protocol, host, port
number, file, and handler.
|
URL(String protocol,
String host,
String file) |
Creates a URL from the specified protocol
name, host name, and file name.
|
URL(URL context,
String spec) |
Creates a URL by parsing the given spec within a specified context.
|
URL(URL context,
String spec,
URLStreamHandler handler) |
Creates a URL by parsing the given spec with the specified handler
within a specified context.
|
-
-
Constructor Detail
-
URL
public URL(String protocol,
String host,
int port,
String file,
URLStreamHandler handler)
throws MalformedURLException
Creates a URL object from the specified
protocol, host, port
number, file, and handler. Specifying
a port number of -1 indicates that
the URL should use the default port for the protocol. Specifying
a handler of null indicates that the URL
should use a default stream handler for the protocol, as outlined
for:
java.net.URL#URL(java.lang.String, java.lang.String, int,
java.lang.String)
If the handler is not null and there is a security manager,
the security manager's checkPermission
method is called with a
NetPermission("specifyStreamHandler") permission.
This may result in a SecurityException.
No validation of the inputs is performed by this constructor.
- Parameters:
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
handler - the stream handler for the URL.
- Throws:
MalformedURLException - if an unknown protocol is specified.
SecurityException - if a security manager exists and its
checkPermission method doesn't allow
specifying a stream handler explicitly.
- See Also:
System.getProperty(java.lang.String),
setURLStreamHandlerFactory(
java.net.URLStreamHandlerFactory),
URLStreamHandler,
URLStreamHandlerFactory.createURLStreamHandler(
java.lang.String),
SecurityManager.checkPermission(java.security.Permission),
NetPermission
-
URL
public URL(URL context,
String spec,
URLStreamHandler handler)
throws MalformedURLException
Creates a URL by parsing the given spec with the specified handler
within a specified context. If the handler is null, the parsing
occurs as with the two argument constructor.
- Parameters:
context - the context in which to parse the specification.
spec - the String to parse as a URL.
handler - the stream handler for the URL.
- Throws:
MalformedURLException - if no protocol is specified, or an
unknown protocol is found, or spec is null.
SecurityException - if a security manager exists and its
checkPermission method doesn't allow
specifying a stream handler.
- See Also:
URL(java.lang.String, java.lang.String,
int, java.lang.String),
URLStreamHandler,
URLStreamHandler.parseURL(java.net.URL,
java.lang.String, int, int)
-
Method Detail
-
getDefaultPort
public int getDefaultPort()
Gets the default port number of the protocol associated
with this URL. If the URL scheme or the URLStreamHandler
for the URL do not define a default port number,
then -1 is returned.
- Returns:
- the port number
- Since:
- 1.4
-
getHost
public String getHost()
Gets the host name of this URL, if applicable.
The format of the host conforms to RFC 2732, i.e. for a
literal IPv6 address, this method will return the IPv6 address
enclosed in square brackets ('[' and ']').
- Returns:
- the host name of this
URL.
-
getFile
public String getFile()
Gets the file name of this URL.
The returned file portion will be
the same as getPath(), plus the concatenation of
the value of getQuery(), if any. If there is
no query portion, this method and getPath() will
return identical results.
- Returns:
- the file name of this
URL,
or an empty string if one does not exist
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|