我正在使用ZipInputStream从位于我的
Android资产文件夹的ZIP文件中读取文件:它的工作原理很慢,因为它必须使用getNextEntry()顺序读取它,并且有相当多的文件.
如果我将ZIP文件复制到SD卡上,使用ZipFile.getEntry时,阅读速度非常快,但是我没有找到使用ZipFile资源文件的方法!
有没有办法以快速方式访问资产文件夹中的ZIP?或者我真的需要将ZIP复制到SD卡?
(BTW,万一有人想知道为什么我这样做:应用程序大于50 MB,所以为了在Play商店获得它,我必须使用扩展APK;但是,由于这个应用程序也应该被放入亚马逊App Store,我必须使用另一个版本,因为亚马逊不支持扩展APK,自然…我认为访问ZIP文件在两个不同的位置将是一个简单的方法来处理这个,但唉.. .)
解决方法
这对我有用:
private void loadzip(String folder,InputStream inputStream) throws IOException
{
ZipInputStream zipIs = new ZipInputStream(inputStream);
ZipEntry ze = null;
while ((ze = zipIs.getNextEntry()) != null) {
FileOutputStream fout = new FileOutputStream(folder +"/"+ ze.getName());
byte[] buffer = new byte[1024];
int length = 0;
while ((length = zipIs.read(buffer))>0) {
fout.write(buffer,length);
}
zipIs.closeEntry();
fout.close();
}
zipIs.close();
}