我正在使用 ZipInputStream
从位于我的 Android Assets 文件夹中的 ZIP 文件中读取文件:它可以工作,但它真的很慢,因为它必须使用 getNextEntry( )
,文件也挺多的。
如果我将 ZIP 文件复制到 SD 卡上,使用 ZipFile.getEntry
时读取速度非常快,但我没有找到使用 ZipFile
的方法 Assets 文件!
有什么方法可以快速访问 Assets 文件夹中的 ZIP 文件吗?或者我真的必须将 ZIP 复制到 SD 卡吗?
(顺便说一句,如果有人想知道我为什么要这样做:该应用程序大于 50 MB,所以为了在 Play 商店中获取它,我必须使用扩展 APK;但是,因为这个应用程序也应该是放入 Amazon App Store,我必须为此使用另一个版本,因为 Amazon 不支持扩展 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, 0, length);
}
zipIs.closeEntry();
fout.close();
}
zipIs.close();
}
关于android - 从 Android Assets 文件夹中的 ZIP 文件中读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11614949/