我想使用Java(jdk,ant.jar或commons-compress)创建.zip文件。
但是如果ZipEntry的名称包含非英语(例如中文,日语),它将在WinRAR或Windows Compress中显示不可读的代码(在WinRAR中正确压缩显示)。
谁能帮助我!!!
答案 0 :(得分:1)
答案 1 :(得分:1)
尝试使用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();
}
}
答案 2 :(得分:-1)
看看7-Zip-JBinding它是7zip的Java包装器。