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 ].