The URL (Uniform Resource Locator) object represents the Uniform Resource Locator, which is a pointer to the Internet "resource". A resource can be a simple file or directory, or a reference to a more complex object, such as a query to a database or search engine. In general, URLs can consist of protocol names, hosts, ports, and resources that meet the following formats:
Protocal://host:port/resourcename
For example, the following URL address:
Http://www.baidu.com
The JDK also provides a URI (Uniform Resource Identifiers) class whose instance represents a uniform resource identifier, and the Java URI cannot be used to locate any resource, its only function is parsing. In response, the URL contains an input stream that can be opened to the resource, so the URL can be interpreted as a special case of the URI.
The URL class provides multiple constructors for creating a URL object, and once you have the URL object, you can call the following common methods to access the resource corresponding to the URL.
String getFile (): Gets the resource name for this LRL.
String gethost (): Gets the host name for this URL.
String GetPath (): Gets the path portion of this URL.
int Getport (): Gets the port number for this URL.
String getprotocal (): Gets the protocol name for this URL.
String Getquery (): Gets the query string portion of this URL.
Urlconnecton openconnection (): Returns a URLConnection object that represents the connection to the remote object referenced by the URL.
Inoutstream OpenStream (): Opens a connection to this URL and returns a inputstream that is used to read the URL resource.
Using URLs to access network resources