我是一名有用的助手,可以为您进行文本翻译。
我被卡在这个问题上了。我想要从zip文件中只打印顶层目录。例如,我有一个具有以下结构的zip文件:
Sample.zip
- sound
- game
-start.wav
-end.wav
- Intro
- custom
- Scene
- fight
- Angle
..............
上图显示:Sample.zip有2个文件夹(sound和custom),在sound文件夹里有2个文件夹game和Intro等等...
现在我知道如何打开和获取zip文件中的目录:例如(工作代码)
try {
appFile = ("../../Sample.zip"); // just the path to zip file
ZipFile zipFile = new ZipFile(appFile);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if(entry.isDirectory()){
String dir = entry.getName();
File file = new File(dir);
System.out.println(file.getParent());
}
}
} catch (IOException e) {
System.out.println("Error opening Zip" +e);
}
现在我也知道可以使用
.getParent()
(如上所示)来获取顶级目录,但是上述实现没有生效。它会列出所有的目录,例如: null
sound
game
null
custom
scene
Angle
我的问题是如何只打印顶级文件夹,在上述情况下,即
sound
和custom
?如果有任何提示,我将不胜感激。