Today in the project encountered through the Web upload files to the file system, Chinese file name garbled, step-by-step to troubleshoot the HTTP communication process of the codec (through Utf-8) did not find the problem. The default character set for the operating system is also utf-8. Printing System.getproperty ("file.encoding") through the log is also utf-8 .... It's a mess. Finally, through the search data, found that through the Java file name encoding and System.getproperty ("sun.jnu.encoding") related to print this environment properties found that the output is an ANSI code, and finally found the issue of the point of explosion, Fix the problem by setting System.setproperty ("Sun.jnu.encoding", "Utf-8") in your program.
By solving the problem, we conclude that sun.jnu.encoding affects the creation of file names, while file.encoding affects the contents of the file.
So, when we use Java processing Chinese files, if found that the Chinese content of the file is not garbled, and the Chinese name of the file is garbled, we should think more about the difference between sun.jnu.encoding and file.encoding.