嘿,我在应用程序中使用了很多字符串,我使用的 .txt 文件有大约 14000 行..并且每 3-10 行分为诸如 ... ..
说到性能/速度,我应该将这些节放入数据库中,还是通过.txt文件逐行读取并检查节号是否是当前节号?这会影响速度/性能吗?
我还可以将每约 2000 行划分到不同的 .txt 文件中,这样需要遍历的行就会更少。这是一种糟糕的数据存储方式吗?谢谢
Hey, I have a lot of Strings that I use into my app, the .txt file that I use has ~14000 lines.. and each 3-10 lines are divided into sections like <String="Chapter I"> ... </String> ..
Speaking of performance/speed, should I put the sections into a Database, Or read line by line through the .txt file and check if the section number is the current one? Will this affect speed/performance?
I could also divide each ~2000 lines into a different .txt file so there would be less lines to go through. Is this a bad way of storing data? Thanks
发布评论
评论(3)
我认为 sqlite 可以解决问题。它可能比解析文本文件快得多,而且您不必维护自己的临时文本数据库,也不必首先构建解析器。基本上,使用它,它的方式更容易。
I think sqlite would do the trick. It will probably be way faster than parsing a text file, plus you wont have to maintain the headache of your own ad hoc text database, or build a parser in the first place. Basically, use it, its way easier.
在 Android 中处理字符串的标准方法是将它们放入 res/values/strings.xml 中(我很确定如果您愿意,您可以在该目录中拥有多个字符串文件)。如果您在 Eclipse 中进行开发,它将自动使用常量填充 R 类(资源类),您可以使用这些常量在代码中引用这些字符串:
或者在 XML 布局中:
或者如果您正在做一些更自定义的事情,您可以使用:
我肯定会选择这个而不是 .txt 文件。这容易多了。所有的工作都为您完成!请阅读这篇 Android 文章来了解它。
The standard way to deal with Strings in Android is to put them into res/values/strings.xml (I'm pretty sure you can have multiple String files in that directory if you like). If you are developing in Eclipse it will automatically populate the R class (the resource class) with constants that you can use to reference these Strings in your code:
Or in XML layouts:
Or if you're doing something more custom you can use:
I would definitely choose this over a .txt file. It's much easier. All the work is done for you! Have a read of this Android article about it.
这就是数据库的用途。使用它。
This is what a database is for. Use it.