700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > zipfile java 解压速率 使用java.util.ZipFile在同一层次中解压缩zipfile

zipfile java 解压速率 使用java.util.ZipFile在同一层次中解压缩zipfile

时间:2019-02-17 18:21:40

相关推荐

zipfile java 解压速率 使用java.util.ZipFile在同一层次中解压缩zipfile

given a zip file with multiple nested directory structure, how do I unzip it into the same tree structure?

does ZipFile.entries() provide the enumeration in any order?

解决方案

Zip doesn't offer directory structure per se. The tree alike structure is built by having full path of each entry. ZipFile enumerates the entries in the same way they have been added to the file.

Note: java.util.ZipEntry.isDirectory() just tests if the last character of the name is '/', that's how it works.

What you need to extract the files into the same directory. Parse then name like that:

for(ZipEntry zipEntry : java.util.Collections.list(zipFile.entries())){//lazislav

String name = zipEntry.getName();

int idx = name.lastIndexOf('/');

if (idx>=0) name=name.substring(idx)

if (name.length()==0) continue;

File f = new File(targetDir, name);

}

That shall do it more or less (you still need to take care of duplicate file names, etc)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。