hdo*_*ort 13 zip android assets
我正在使用以下位置读取位于我的Android资源文件夹中的ZIP文件中的文件ZipInputStream
:它可以工作,但它确实很慢,因为它必须按顺序读取它getNextEntry()
,而且有很多文件.
如果我将ZIP文件复制到SD卡上,使用时读取速度非常快ZipFile.getEntry
,但我找不到使用ZipFile
资产文件的方法!
有没有办法快速访问资产文件夹中的ZIP?或者我真的要将ZIP复制到SD卡吗?
(顺便说一句,如果有人想知道为什么我这样做:应用程序大于50 MB,所以为了在Play商店中获取它我必须使用扩展APK;但是,因为这个应用程序也应该放入亚马逊App Store,我必须使用另一个版本,因为亚马逊不支持扩展APK,当然......我认为在两个不同的位置访问一个ZIP文件将是一个简单的方法来处理这个,但唉...... .)
您可以通过以下方式创建 ZipInputStream:
ZipInputStream zipIs = new ZipInputStream(context.getResources().openRawResource(your.package.com.R.raw.filename));
ZipEntry ze = null;
while ((ze = zipIs.getNextEntry()) != null) {
FileOutputStream fout = new FileOutputStream(FOLDER_NAME +"/"+ 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();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10298 次 |
最近记录: |