How to obtain the path in Java

Source: Internet
Author: User

To obtain the current path of a Java class, call class. getresource to obtain the Chinese path. The returned result is 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: The Chinese path is D:/work/network access control/

% E5 is the hexadecimal encoded URL for Chinese characters. When the result is in new file (), the exist value is always false, so that dom4j cannot obtain the XML file.

Now, you can use urldecoder. decode to convert 16 to Chinese and then 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.