Differences between system attributes sun. JNU. encoding and file. encoding of Java

Source: Internet
Author: User

Differences between system attributes sun. JNU. encoding and file. encoding of Java

Sun. JNU. Encoding affects File Name Creation, while file. Encoding affects file content.

Therefore, when we use Java to process Chinese files, if we find that the Chinese content of the file is not garbled and the Chinese name of the file is garbled, we should consider sun. JNU. encoding and file. the difference between encoding.

Org.apache.tools.zip. But sometimes the Chinese file name after packaging may contain garbled characters. Why? View the org.apache.tools.zip. zipoutputstream API and you will find instructions on its getencoding () method: "The encoding to use for filenames and the file comment.", run the following statement:

 
Org.apache.tools.zip. zipoutputstream out = new org.apache.tools.zip. zipoutputstream (New Java. io. fileoutputstream ("D:/temp/testfile.zip"); system. out. println ("out. getencoding () = "+ out. getencoding ());

The execution result is as follows:

Out. getencoding () = NULL

The problem is here. After org.apache.tools.zip. zipoutputstream is created, set it manually:

 
Out. setencoding (system. getproperty ("Sun. JNU. encoding "));

The Chinese name can be properly displayed after packaging.

Refer to answer about Sun. JNU. Encoding provided by idea ],

Reference 2: Producer API ],

reference 3: Source Code of struct ].

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.