Java system attributes sun.jnu.encoding and file.encoding differences __java

Source: Internet
Author: User

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.




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.