Reputation: 3
I'm using a pre-built method that returns an object of type File. It's known that the file I'm receiving is a zip of a directory. What's the quickest way I could check if it's empty i.e. has no files? Do i need to necessarily extract it?
EDIT: I think I may have ambiguously worded the title. My requirement is to check that the number of entries in the zipped directory are zero. Sorry for any confusion.
Upvotes: 0
Views: 4413
Reputation: 159086
To check is a zip file is empty:
boolean isEmpty;
try (ZipFile zipFile = new ZipFile(file)) {
isEmpty = (zipFile.size() == 0);
}
Upvotes: 3