android - 从 Android Assets 文件夹中的 ZIP 文件中读取文件

标签 android zip assets

我正在使用 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/

相关文章:

java - 如何防止 APK 中的 Assets 文件被逆向工程

ruby-on-rails - 每次部署后回形针文件都会被删除

android - 使用 Android 智能手机检测红外光点

java - 为什么示例作者对正交相机的宽度和高度进行硬编码?(LibGdx Zombie Bird 教程)

android - 将 ImageView 正好放在 VideoView 之上

python - 如何使用 python 提取封闭的 zip

PHP:无法上传 ZIP 文件

android - 使用cordova将android图库中的图片分享到cordova应用程序

python - 如何使用 python 的 ziplib 文件压缩巨大的纯文件 (+20GB)

css - Rails 3.1 中的 CSS 样式有什么问题?