Extract uncompressed size of zip file embedded in

2019-09-18 00:35发布

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)?

1条回答
Lonely孤独者°
2楼-- · 2019-09-18 01:36

getSize() returns uncompressed size. This is in opposite to getCompressedSize(). 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.

查看更多
登录 后发表回答