要成功打包zip文件,我必须使用特殊字符对文件进行编码,但是稍后我需要将其恢复为纯文本格式。我必须编码,因为如果文件名(* / SPACE)及其组合中出现奇怪字符,则会出现异常。环境是Windows,一定是这样。如何迭代现有的zip并重命名其中的所有文件?结果可以是相同的zip文件,也可以是其他无法测量的文件。我的代码不起作用:
final String name = project.getUuid() + ".zip";
final File zip = new File(downloadFolder, name);
ZipUtil.pack(archiveFolder, zip); // create zip with encoded file names
final StringZipEntryTransformer stringZipEntryTransformer = new StringZipEntryTransformer() {
protected String transform(ZipEntry zipEntry, String input) throws IOException {
String decodedString = URLDecoder.decode(input, "UTF-8"); // code never comes into this abstract method I guess because of the path parameter in line 10. it is a first parameter
return decodedString;
}
};
ZipEntryTransformerEntry zipEntryTransformerEntry = new ZipEntryTransformerEntry(File.pathSeparator + "*", stringZipEntryTransformer);
final String projectNameZip = project.getName() + ".zip";
final File transformedZip = new File(downloadFolder, projectNameZip);
ZipUtil.transformEntry(zip, zipEntryTransformerEntry, transformedZip);
问题在于,从未调用过 transform 方法,但是我不确定是什么原因。