Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA ZipFile entries() method doesn't see directories

Tags:

java

zip

I'm working on digital documents and digital signatures and I've stumbled upon a problem.

Input: documentX.adoc - zip file with files and folders inside.

I need to get all the content in the input file - a list of dirs and files.

What do I do:

ZipFile adocFile = new ZipFile(documentXFileName);
ArrayList <String> adocFiles = new ArrayList<String>();
Enumeration <? extends ZipEntry> entries;
entries = adocFile.entries();
for (entries = adocFile.entries(); entries.hasMoreElements();)
{
    adocFiles.add(entries.nextElement().getName());
}

I've tried to create ArrayList < ZipEntry > and add ZipEntries instead of names - still nothing. Maybe there is some other way? Strange thing is, that ZipEntry has a .isDirectory() method...

Thanks for help, Martin

like image 430
Brutus Avatar asked Nov 18 '10 14:11

Brutus


1 Answers

From the documentation:

A directory entry is defined to be one whose name ends with a '/'.

It is not necessary to store directories in a ZIP file - they are optional entries. It is possible to store a byte sequence with the path foo/bar.txt without an entry called foo. Zip tools may provide the illusion that such things exist within the archive even if they don't.

like image 162
McDowell Avatar answered Oct 27 '22 01:10

McDowell