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 有大小限制吗?谢谢!