The java+linux of Chinese environmental problems __linux

Source: Internet
Author: User


Took over a new project, encountered a problem, is to use the Java File.listfiles method to get the file under the path, the problem is: Get the Chinese filename is garbled ... The symptom is that files are not found through the Java file API.


Initially suspected of environmental problems, the first step to troubleshoot environment variables:

# Export environment variables in Linux proc
cat/proc/10643/environ| TR ' n '


Note: Replace the process ID yourself


If you find no lang, add the configuration:

Export lang= "en_US. UTF-8 "


But the problem remains after the restart process.


Next, look at Java's implementation of the file class, found by filesystem corresponding native method, which is the code of C, the next suspicion is "lc_xxx" the environment variable interference.


Based on this idea, the environment variables are added:

Export Lc_all= "en_US. UTF-8 "


The problem disappears after the reboot.


Summarize:

An estimate is a link to the START process, introducing a configuration of lc_xxx, which causes the locale configuration of C to be changed to match the encoding and expected of the obtained filename. The solution is more brutal and covers all configurations through Lc_all.


Report:

Java Configuration Chinese environment
-dfile.encoding=utf-8-duser.country=us-duser.language=en

Export Lc_all= "en_US. UTF-8 "Export lang=" en_US. 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.