提取嵌入jar中的压缩文件的未压缩大小 [英] Extract uncompressed size of zip file embedded in jar

查看:140
本文介绍了提取嵌入jar中的压缩文件的未压缩大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jar中嵌入了一个zip文件,想要读取未压缩的大小。我目前的做法是:

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();
}

这当然很脏,当我嵌入我的时候也不行使用JSmooth将jar文件放入exe文件中。

This is of course rather dirty and also doesn't work when I embed my jar file into an exe file using JSmooth.

有没有更好的方法(不复制zip文件)?

Is there a better way of doing this (without copying the zip file)?

推荐答案

getSize()返回未压缩的大小。这与 getCompressedSize()相反。并且两者都可以与拉链一起使用,无论是作为独立文件存储还是嵌入到其他zip中。
不幸的是我不知道你怎么能用JSmooth解决这个问题。

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.

如果 files.zip 是您的文件可以在构建时检查条目大小,并将结果放入属性文件中。这是一个补丁,但它会起作用。

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.

这篇关于提取嵌入jar中的压缩文件的未压缩大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆