Solution to the problem of Chinese garbled code in Java compressed zip file

Usually, after using java to package files to generate compressed files, there are two places where there will be garbled Code: 1. The Chinese garbled code of the content. Many people on the Internet have given solutions to this problem. There are two main methods: one is to modify the source code of sun; The other is to use the open source class library org apache. tools. zip. Zipoutputstream and org apache. tools. zip. Zipentry, these two classes are ant Jar, which can be downloaded and used directly. There is no doubt that it is more convenient to choose the latter

2. Chinese garbled code problem of compressed file comments: zos Setcomment ("Chinese test"); There are few corresponding solutions to this problem on the Internet. There is no problem with the test class created in the project on your own machine, but it is always garbled in the company's project by using the method of setting coding (zos. SetEncoding ("GBK") Finally, the problem is found. The coding method of the test project is GBK, while the default coding of the company's project is UTF-8, so the test project is OK, but there are problems in the company's project.

org. apache. tools. zip. Zipoutputstream uses the encoding method of the project by default. Theoretically, UTF-8 also supports Chinese. I really can't figure out why it is still garbled. It can be solved by changing the SetEncoding method to GBK

The example code for the above problem is as follows:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>