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 "