Java创建的.zip文件不支持中文(utf-8)

我想使用Java(jdk,ant.jar或commons-compress)创建.zip文件。

但是如果ZipEntry的名称包含非英语(例如中文,日文),它将在WinRAR或Windows Compress中显示不可读的代码(在WinRAR中正确压缩显示)。

谁能帮我!!!

你已经击中了前25个java bug中的一个 。

好消息是这已经解决了。 坏消息它只在JDK7中修复。 有关详情,请参阅此条目 。

另外,您可以使用Arcmexer (readonly)。

通过使用apache commons compress来尝试这个,

import java.io.*; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; public class ZipFiles { public static void main(String[] args) throws Exception{ ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(new FileOutputStream("测试.zip")); zipOut.setEncoding("Cp437"); // This should handle your "special" characters zipOut.setFallbackToUTF8(true); // For "unknown" characters! zipOut.setUseLanguageEncodingFlag(true); zipOut.setCreateUnicodeExtraFields( ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NOT_ENCODEABLE); zipOut.putArchiveEntry(new ZipArchiveEntry("测试.xml")); zipOut.putArchiveEntry(new ZipArchiveEntry("test.xml")); zipOut.closeArchiveEntry(); zipOut.flush(); zipOut.close(); } } 

看看7-Zip-JBinding它是7zip的Java包装器。