srikanth-lingala / zip4j

A Java library for zip files and streams
Apache License 2.0
2k stars 307 forks source link

renameFiles只工作一次 #516

Closed n9tank closed 9 months ago

n9tank commented 9 months ago

将错误的文件夹,修正为文件,但是renameFiles只工作一次这是为什么? public static String wzip(File f) { try { ZipFile z=new ZipFile(f); List fhs=z.getFileHeaders(); int i=fhs.size(); int k=16; while (k < i) { k >>= 1; } HashMap hp=new HashMap(k); while (--i >= 0) { FileHeader fh=fhs.get(i); String na=fh.getFileName(); int le=na.length() - 1; char c=na.charAt(le); if (fh.getCompressedSize() != 0l || fh.getUncompressedSize() != 0l) { String rs; if (c == '/'||c=='\') { fh.setDirectory(false); rs=na.substring(0,le); c=na.charAt(--le); if(c=='/'||c=='\'){ rs+=(char)(c+1); } }else continue; hp.put(na,rs); } z.renameFiles(hp); return "完成"; } } catch (Exception e) { } return "失败"; }

n9tank commented 9 months ago

这个方法运行的结果

0.zip .dev/ 16B .extv/ 4B .sstv/ 6B .timv/ 30B out.zip .dev/ 16B .extv/ 4B .sstv/ 6B .timv 30B