Java URI and URL issues

Source: Internet
Author: User
Tags xsl

The file class has two seemingly similar methods Touri () and Tourl (), both of which convert files to a link that can be accessed by the network. URIs and URLs have a wider range of applications than URIs.


So why use Touri () instead of Tourl ()? This is easier if you want to convert the file to a URL. Because there is a bug in Tourl ().

When file is converted to a URI, the special words in the link will be such as # or! Encoding, and Tourl () does not.
If you convert "c:documents and settingstest.xsl"
Touri () obtained: File:/c:/documents and settings/test.xsl
Tourl () obtained: File:/c:/documents and settings/test.xsl

That is to say Touri () translates the spaces into, and Tourl () nothing. Sun also mentions this bug (4273532,6179468).
Although there is no problem with translation in the browser, some browsers are automatically translated. However, many programs or components will throw an exception to such a path, and there is a real example of this bug.
So to convert the file to a URL, use File.touri (). Tourl () instead of File.tourl ()

Java URI and URL issues

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.