I have a zip file embedded in my jar and want to read the uncompressed size. My current way of doing this:
ZipFile zipFile = new ZipFile(new File(this.getClass().getClassLoader().getResource("files.zip").toURI()));
Enumeration<? extends ZipEntry> e = zipFile.entries();
long installedSize = 0;
while (e.hasMoreElements()) {
ZipEntry entry = e.nextElement();
installedSize += entry.getSize();
}
This is of course rather dirty and also doesn't work when I embed my jar file into an exe file using JSmooth.
Is there a better way of doing this (without copying the zip file)?
getSize()
returns uncompressed size. This is in opposite togetCompressedSize()
. And both work fine with zips either they are stored as stand alone file or embedded into other zip. Unfortunately I do not know how can you solve this with JSmooth.If
files.zip
is your files you can check the entries size at build time and put the result into properties file. It is a patch, but it will work.