is there a way to get the Size of a folder with TrueZip without doing it myself recursively? I'm concerned about the runtime since I'm dealing with Archives that contain lots of files.
Using TrueZip 7.7.9
is there a way to get the Size of a folder with TrueZip without doing it myself recursively? I'm concerned about the runtime since I'm dealing with Archives that contain lots of files.
Using TrueZip 7.7.9
Copyright © 2021 Jogjafile Inc.
OK, here is a simple test using only the standard Java 7 API; it uses the bundled JSR 203 implementation for zips:
The zip above only contains files at the top level, not directories.
This means that you can use this API to correctly compute the size of files in a zip; without the need to uncompress.
You use Java 7; therefore, what you want to do is probably to use a
FileVisitor
which computes the size of all regular files for you.Here I have made a crude hack which uses
Files.size()
; note that in aFileVisitor
, when you visit a filesystem entry which is not a directory, you have an instance ofBasicFileAttributes
coming along from which you can retrieve thesize()
.Javadoc here; and use
Files.walkFileTree()
.With Java 8, this is much simpler, you could use
Files.find()
instead.