对于我的 android 应用程序,我想使用一个大型数据库(大约 45 MB)。
一个解决方案是将(拆分的)数据库包含在 Assets 文件夹中,并在第一次启动时将其复制到数据库目录。
但这会占用磁盘空间两次 - 一次在无法删除文件的 Assets 文件夹中,一次在文件已复制到的数据库目录中。
所以我宁愿在第一次启动时从互联网(网络服务器)下载数据库。我怎么能这样做?我可以下载一个完整的SQLite文件并保存到数据库目录吗?还是我应该使用用于填充数据库的 JSON 数据文件?
最佳答案
One solution would be to include the (splitted) database in the assets folder and copy it to the database directory on the first startup.
不必拆分,只需压缩即可。参见 SQLiteAssetHelper
举个例子。
How could I do this?
使用HttpUrlConnection
。或者,使用 HttpClient
。
Can I download a complete SQLite file and save it to the database directory?
是的。使用 getDatabasePath()
获取要使用的正确本地路径。
Or should I rather go with JSON data files that are used to populate the database?
你可以,但对于 45MB,那会非常慢。
关于android - 从 Internet 下载 SQLite 数据库并加载到 Android 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10254872/