访问.sqlite数据库(大于1Mb的大小)的机器人 [英] accessing .sqlite database (>1Mb size) in android

查看:92
本文介绍了访问.sqlite数据库(大于1Mb的大小)的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的图书馆应用程序,并具有与.sqlite文件存储的书籍。每本书的SQLite数据库文件是10MB左右大小。我第一次尝试把它的资产文件夹,然后将其复制到数据库/文件夹,但由于该文件是>为1Mb这给了我一个IOException。然后我试图从原始文件夹,但它仍然给了我IOException异常访问它。那么,什么是访问这样一个文件的正确方法。此外,在未来的应用程序可能需要从服务器下载这些文件,所以在这种情况下,我应该在哪里存储这些数据库文件?

I am working on a library app and have books stored as .sqlite files. Each book's sqlite database file is about 10MB in size. I first tried to put it in assets folder and then copying it to database/ folder but since the file is >1Mb this gives me an IOException. Then I tried to access it from raw folder but its still giving me IOException. So, what is the correct way to access such a file. Also, in future the app might need to download such files from server, so in that case where should I store such database files?

谢谢!

推荐答案

的Andr​​oid 3.0之前,你的不允许打开的文件超过1MB 大。

Before Android 3.0 you are not allowed to open files larger than 1mb.

从链接:[P] rior到Android 2.3,任何COM pressed资产超过1 MB的uncom pressed大小的文件不能从APK读

From the link: [P]rior to Android 2.3, any compressed asset file with an uncompressed size of over 1 MB cannot be read from the APK.

下面是一些解决方法:

  1. 也许你想看看数据库的大小缩小,这可能是通过你自己的,或通过删除某些条目,你并不需要/想。

  1. Perhaps you want to look into shrinking the size of the databases, and that might be by making your own, or by removing some of the entries that you do not need/want.

另一种解决办法是卸载数据库,你可以访问,并要求应用程序访问网络来获取必需从该服务器的数据的服务器。我能想象一个不错的REST的API来做到这一点。

Another solution would be to offload the databases to a server that you have access to and require the application to access the web to get the data that is necessary from this server. I can imagine a nice RESTful API to do this.

这篇关于访问.sqlite数据库(大于1Mb的大小)的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆