- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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/
下面是代码片段。 while (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream in
我有 Java 代码,它传入一个 Zip 文件列表,其中一个文件的格式故意错误。该 Zip 文件位于列表末尾。 我的代码看起来有点像: System.out.println("Hi Stinky Pe
如果我使用包含一些带有变音符号的文件(例如 1-2GF-969##JÖN.pdf)的 zip 文件运行以下程序,我会得到 IllegalArgumentException。 我的应用程序必须支持所有语
下面是一些从仅包含一个文件的 zip 文件中提取文件的代码。但是,提取的文件与通过 WinZip 或其他压缩实用程序提取的同一文件不匹配。如果文件包含奇数个字节,我预计它可能会关闭一个字节(因为我的缓
我正在尝试从 ZIP 存档中读取 XML 文件。相关代码如下: ZipInputStream zis = new ZipInputStream(is); ZipEntry entry = zis.ge
我正在开发一个电子阅读器应用程序(使用 skyepub ),它基本上将加密的书籍下载到文件系统中(并将解密 key 保存在数据库中),当用户尝试阅读它时,它会加载将书存入内存并解密。 问题是有些书的第
我正在尝试从 ZIP 存档中读取 XML 文件。相关代码如下: ZipInputStream zis = new ZipInputStream(is); ZipEntry entry = zis.ge
有java.io.ZipInputStream膨胀和java.io.ZipOutputStream这会泄气。 但有时我不希望这样。有时,当使用接受 InputStream 的第三方 API 时,我想要
我想知道是否有一种方法可以直接从 ZipFile/ZipInputStream 读取特定文件,而不必遍历整个条目集。我想这可能是一个很大的开销,如果存档包含大量文件。有没有更好的办法? 我知道这可以用
因此,在 ZIP 文件的末尾,例如最后 64K,有一个中央目录,从中您可以看到 ZIP 文件本身包含的内容。 现在我已将 ZIP 文件加载到 ZipInputStream 中,在此之前我已声明一个 l
我有一个 JSF 应用程序(Majorra 2.1.20、PrimeFaces 4.0-SNAPSHOT、OmniFaces 1.4.1,在 Glassfish 3.1.2 上运行),可以在 Fire
那么使用ZipInputStream时,要在WEB上获取Zip文件的InputStream,使用时是否会将整个ZIP文件下载到用户计算机中? 例如,如果程序使用 ZipInputStream 来查看
在我们完全读取流之前,是否可以找到/估计 ZipInputStream 的大小? 例如,我们可以在读取用户数据之前使用 getNextEntry 获取条目的元数据。 Inputstream 有一个方法
我可以通过 ZipInputStream,但在开始迭代之前,我想获取迭代期间所需的特定文件。我该怎么做? ZipInputStream zin = new ZipInputStream(myInput
我正在使用 AsyncTask 解压缩文件,一切似乎都进行得很顺利(ZIP 存档中的所有文件都已提取),但我的解压缩方法从未完成。 这是我的解压类的源代码: public class MyUnzipp
假设我们有这样的代码: File file = new File("zip1.zip"); ZipInputStream zis = new ZipInputStream(new FileInputS
我们正在尝试修改 2007 MS Excel 中的 XML 文件之一。为此,将使用 Java 的 ZipInputStream 解压缩 xlsx 文件,然后使用 ZipOutputStream 将其复
我正在尝试从 zip 中解压缩特定文件。我首先得到一个ZipInputStream: ZipInputStream zipIn = new ZipInputStream(new BufferedInp
我做了this问题,我看到存在一个名为 ZipInputStream 的构造函数: ZipInputStream(BufferedInputStream, 字符集) 但是调试器向我抛出错误: ZipI
private byte[] loadClassData(String className) { ZipInputStream in = null; FileInputStream f
我是一名优秀的程序员,十分优秀!