假设我们有这样的代码:
File file = new File("zip1.zip");
ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
假设您有一个包含以下内容的 .zip 文件:
zip1.zip
你好.c
世界.java
文件夹1
foo.c
bar.java
foobar.c
zis.getNextEntry() 将如何遍历它?
它会返回 hello.c、world.java、folder1、foobar.c 并完全忽略 folder1 中的文件吗?
或者它会返回 hello.c、world.java、folder1、foo.c、bar.java,然后是 foobar.c?
它甚至会返回 folder1,因为它在技术上是一个文件夹而不是一个文件吗?
谢谢!
最佳答案
嗯……让我们看看:
ZipInputStream zis = new ZipInputStream(new FileInputStream("C:\\New Folder.zip"));
try
{
ZipEntry temp = null;
while ( (temp = zis.getNextEntry()) != null )
{
System.out.println( temp.getName());
}
}
输出:
New Folder/
New Folder/folder1/
New Folder/folder1/bar.java
New Folder/folder1/foo.c
New Folder/foobar.c
New Folder/hello.c
New Folder/world.java
关于java - ZipInputStream.getNextEntry() 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11784102/