gpt4 book ai didi

java - zipInputStream 的大小始终为 512 字节?

转载 作者:行者123 更新时间:2023-12-01 15:42:52 26 4
gpt4 key购买 nike

    private byte[] loadClassData(String className) {
ZipInputStream in = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(jarPath);
in = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
while ((entry = in.getNextEntry()) != null) {
if (entry.getName().contains(".class")) {
String outFileName = entry.getName()
.substring(0, entry.getName().lastIndexOf('.'))
.replace('/', '.');
if (outFileName.equals(className)) {
if (entry.getSize() == -1) {
Log.e("loadClassData", "can't read the file!");
return null;
}
byte[] classData = new byte[(int) entry.getSize()];
in.read(classData);
return classData;
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fis.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}

在调试中,我总是得到“in”的大小是512字节,这样我就无法获取文件的其余部分,我不知道为什么。ZipInputStream有大小限制吗?谢谢你!

最佳答案

 if (entry.getSize() == -1) {

ZipEntry.getSize() 返回条目数据的未压缩大小,或者-1(如果未知)。。您需要删除此检查。

I always get the size of "in" is 512 bytes

你如何检查这个? ZipInputStream 没有大小属性​​。您检查的任何内容都是无关的。

This似乎是 ZipInputStream 使用的一个很好的规范示例。

关于java - zipInputStream 的大小始终为 512 字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7734969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com