android - Android: Efficiently copy a zip containing thousands of files from assets to internal storage
问题描述
TL;DR: Is there a way to copy a zip file containing thousands of files from Android assets to internal storage that is more efficient than using ZipInputStream
?
My Android app has several assets that need to be copied into device storage upon initial launch. These are stored as zip files in assets and are copied via ZipInputStream
as described here (in the unzip
method). There are 10 zip files totalling 36MB, and the unzip/copy process takes about 3 seconds.
The problem: I need to add a new asset that is 39MB, but it adds about 30 seconds to the process. My hunch is that this is because the asset consists of 5500 files (averaging about 7KB each). Since I need the assets at launch, running this in a background service is not an option, and 30+ seconds is a really long time to show a splash screen.
This post suggests using ZipFile
instead of ZipInputStream
but it does not seem to work properly in Android as noted here and other S/O posts, and I am experiencing the same ZipException described there (note this is after copying the zip file to internal storage - Android assets only provides a stream, not a file, so the zip must be copied from assets before the ZipFile method can be used).
Is there a more efficient way to go about this?
解决方案
不幸的是 - 没有,因为写入每个文件都包含 3 个主要操作:创建和打开文件以进行写入,将数据写入文件,关闭文件以进行写入。复制这么多文件的最快方法 - 将它们放在一个文件中,例如二进制文件或 sqlite 数据库文件。或者您可以找到一种直接从存档中读取的方法。请记住,您将无法从资产中删除此文件(至少我从未听说过解决方案),所以它对我来说似乎没用。
推荐阅读
- python - Flask 方法 PUT 没有返回一些东西
- docker - mariadb容器上的exec命令出现问题
- php - 如何连接用户选择的今天的日期和小时以将其插入为日期时间
- xml - 使用 XSLT 中单个 xml 字段的计数填充页脚行
- oracle - 在 makefile 中设置动态 ORACLE_HOME
- sql - 比较sql中列号不同的两张表
- python - ungoogled-chromium-windows 构建失败,出现“致命错误:'atlsecurity.h' 文件未找到”
- java - Android耳机插孔按钮接线?
- python-3.x - 如何使用 CEX REST API 下市价单?
- discord.js - Discord.js 在用户角色中搜索的问题