Java URL object initialization and reading content through URLs

Source: Internet
Author: User

First, the URL hierarchy.

The creation of the URL object.

1, public URL (String spec);

URL urlbase=new url ("http://my.oschina.net/u/2308739/admin/new-blog.html");

2, public URL (url context,string spec);

URL urlbase=new url ("http://my.oschina.net/u/2308739/admin/");

URL indexurl=new url (urlbase, "new-blog.html");

3, Public URL (String protocol,string host,string file);

Constructs a URL object by protocol name, hostname, and file name.

New URL ("http", "Http://my.oschina.net", "/u/2308739/admin/new-blog.html");

4, P ublic URL (String protocol,string host,int port,string file);

Constructs a URL object through the protocol name, hostname, port number, and file name.

new URL ("http", "http://my.oschina.net","n", "/u/2308739/admin/new-blog.html");

Second, read the content through the URL

The OpenStream () method of the URL is used to get the object of the Java.io.inputstream class to read the contents of the URL address from the input stream.

The definition of this method is:

Public final InputStream OpenStream () throws IOException;


Java URL object initialization and reading content through URLs

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.