SQLite数据库与文件存储
我想存储结构类型数据(即呼叫日志信息,如姓名、号码、号码类型、日期、时间、持续时间)。哪种方法最好,哪种方法更快? SQLiteDatabase(创建表并插入、删除其中的日志)或使用文件存储(意味着为所有参数创建一个类并使用输入/输出流和可序列化将其对象写入文件中)或我听说的另一种方式是 XML 解析器,但是我不知道这个。
请帮我。提前致谢。
I want to store structure type data (i.e. information of call logs like name, number, type of number, date, time, duration). Which is the best way and which is faster? SQLiteDatabase (make table and insert, delete logs in it) or use file storage (means make one class for all parameters and write their objects in file using input/output Stream and serializable) or the another way i heard about it is XML parser but i don't know this.
Please help me. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这取决于您想要做什么。
如果您的目标是速度,那么 SQLite 将会给您带来很大的损失(特别是如果您将多个插入包装到事务中)。 SQLite 已经针对您提到的所有内容进行了优化,并且很容易利用它可以为您提供的速度。
如果可移植性是您的目标,那么文件可能会稍微容易一些。文件可以非常轻松地来回移动,而 SQLite 可能需要更多的努力。
如果能够搜索是您的目标,那么您不使用 SQLite 就太傻了,因为它非常擅长搜索和过滤结果。
It depends on what you are trying to do.
If your goal is speed, the SQLite will give you a serious run for your money (especially if you wrap multiple inserts into transactions). SQLite has been optimized for everything you mentioned and it would be very easy to leverage the speed it can give you.
If portability is your goal, then files may be a slight bit easier. Files can be moved back and forth very easily easily, whereas SQLite might take some more effort.
If being able to search is your goal, then you'd be a fool not to use SQLite, as it is extremely good at searching and filtering results.
我无法在这里给出非常明智的答案,因为我和您一样对这个主题很陌生,但这里是开发人员页面的链接,其中介绍了不同类型的数据存储。我希望你觉得它有用。 http://developer.android.com/guide/topics/data/data -storage.html
I can't give a very informed answer here because I'm just as new to the subject as you are, but here is the link from the developers page that goes over the different types of data storage. I hope you find it useful. http://developer.android.com/guide/topics/data/data-storage.html
就个人而言,如果您了解数据库的基础知识,我会使用 sqlite 数据库。在 Android 中这非常简单。就速度而言,我不知道哪个更快,但如果你没有数百万个数据集,那也没关系。
Personally, given you know the basics of Databases I would use a sqlite database. It's pretty straight forward in Android. In terms of speed I don't know which is faster, but if you don't have millions of datasets it won't matter.
根据我的经验,大多数情况下文件中的 JSON 就足够了(大多数情况下您需要存储数组或对象或仅存储单个数字或字符串)。我很少需要SQLite(这需要更多时间来设置和使用它)。
In my experience in most cases JSON in a file is enough (mostly you need to store an array or an object or just a single number or string). I rarely need SQLite (which needs more time for setting it up and using it).