Extract uncompressed size of zip file embedded in jar

狂风中的少年 提交于 2019-12-13 07:04:27

问题


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:


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.



来源:https://stackoverflow.com/questions/8560816/extract-uncompressed-size-of-zip-file-embedded-in-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!