Using URLs to access network resources

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.