我必须使用apache-commons-compress-1.x API创建文件zip。
我使用了以下代码:

File fileZip = new File("D:\\file.zip");
ZipEncoding zipEncoding = ZipEncodingHelper.getZipEncoding("UTF8");
ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(fileZip);
zipOut.setEncoding("UTF-8");

File entryFile = new File("D:\\attività.jpg");
String entryName = entryFile.getName();
entryName = new String(entryName.getBytes("UTF-8"), "UTF-8");

ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
entry.setSize(entryFile.length());

FileInputStream fInputStream = new FileInputStream(entryFile);
zipOut.setUseLanguageEncodingFlag(true);
 zipOut.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS);
zipOut.putArchiveEntry(entry);
zipOut.write(IOUtils.toByteArray(fInputStream));
zipOut.closeArchiveEntry();

zipOut.flush();
zipOut.close();


zip条目文件名具有编码错误。如果我使用zip Manager构建的Windows XP打开压缩文件,则文件名为attivit+á.jpg
请帮帮我。

最佳答案



entryName = zipEncoding.encode("attivit\u00E0.jpg");

10-06 03:28