Java fetch path Chinese problem __java

Source: Internet
Author: User

To get the current path of a Java class, get the Chinese path by calling Class.getResource, and return the result as follows:

d:/%e5%b7%a5%e4%bd%9c/%e7%bd%91%e7%bb%9c%e6%8e%a5%e5%85%a5%e6%8e%a7%e5%88%b6/

Note: Chinese path for d:/work/network access control

%e5 is a URL to the Chinese 16 encoding, the result of the new file (), exist always false, resulting in dom4j can not get the XML file.

Now through the use of: Urldecoder.decode will be 16 back to Chinese, can read the file normally

Urldecoder.decode ("/%e5%b7%a5%e4%bd%9c/", "UTF-8")

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.