Android Guides | Samples

Java.Net.URL Class

A Uniform Resource Locator that identifies the location of an Internet resource as specified by .

See Also: URL

Syntax

[Android.Runtime.Register("java/net/URL", DoNotGenerateAcw=true)]
public sealed class URL : Object, ISerializable, IDisposable

Remarks

A Uniform Resource Locator that identifies the location of an Internet resource as specified by .

Parts of a URL

A URL is composed of many parts. This class can both parse URL strings into parts and compose URL strings from parts. For example, consider the parts of this URL: http://username:password@host:8080/directory/file?query#ref:
ComponentExample valueAlso known as
URL.Protocolhttpscheme
URL.Authorityusername:password@host:8080
URL.UserInfousername:password
URL.Hosthost
URL.Port8080
URL.File/directory/file?query
URL.Path/directory/file
URL.Queryquery
URL.Refreffragment

Supported Protocols

This class may be used to construct URLs with the following protocols:
  • file: read files from the local filesystem.
  • ftp:
  • http:
  • https:
  • jar: read JarFile from the filesystem
In general, attempts to create URLs with any other protocol will fail with a MalformedURLException. Applications may install handlers for other schemes using URL.SetURLStreamHandlerFactory(IURLStreamHandlerFactory) or with the java.protocol.handler.pkgs system property.

The URI class can be used to manipulate URLs of any protocol.

[Android Documentation]

Requirements

Namespace: Java.Net
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Java.Net.URL are listed below.

See Also: Object

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 Properties

[read-only]
AuthorityString. Returns the authority part of this URL, or null if this URL has no authority.
[read-only]
ContentObject. Returns the content of the resource which is referred by this URL.
[read-only]
DefaultPortInt32. Returns the default port number of the protocol used by this URL.
[read-only]
FileString. Returns the file of this URL.
[read-only]
HostString. Returns the host name or IP address of this URL.
[read-only]
PathString. Returns the path part of this URL.
[read-only]
PortInt32. Returns the port number of this URL or -1 if this URL has no explicit port.
[read-only]
ProtocolString. Returns the protocol of this URL like "http" or "file".
[read-only]
QueryString. Returns the query part of this URL, or null if this URL has no query.
[read-only]
RefString. Returns the value of the reference part of this URL, or null if this URL has no reference part.
[read-only]
UserInfoString. Returns the user info of this URL, or null if this URL has no user info.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

GetContent(Class[]) : Object
Equivalent to openConnection().getContent(types).
OpenConnection() : URLConnection
Returns a new connection to the resource referred to by this URL.
OpenConnection(Proxy) : URLConnection
Returns a new connection to the resource referred to by this URL.
OpenStream() : Stream
Equivalent to openConnection().getInputStream(types).
SameFile(URL) : Boolean
Returns true if this URL refers to the same resource as otherURL.
static
SetURLStreamHandlerFactory(IURLStreamHandlerFactory)
Sets the stream handler factory for this VM.
ToExternalForm() : String
Returns a string containing a concise, human-readable representation of this URL.
ToURI() : URI
Returns the URI equivalent to this URL.

Protected Methods

Set(String, String, Int32, String, String)
Sets the properties of this URL using the provided arguments.
Set(String, String, Int32, String, String, String, String, String)
Sets the properties of this URL using the provided arguments.