我应该在 android 中使用什么样的文件来引用我存储的信息?
我创建了一个 Android 应用程序,可以计算单词的数值,并为您提供具有相同数值的其他单词的列表。我一直这样做的方式是将单词和值存储在 .properties 文件中。 IE。 .proprties 文件中名为“myWords”的行将包含以下内容:61=you,然后我只需使用 get() 方法来调用它,
IE。 String myString = ResourseBundle.get("myWords").get("61");将返回字符串“you”。有更好的方法吗?我的猜测是,这不是 .properties 文件的正确使用,我想知道是否有另一种方法可以正确执行此操作。我想将文件包含在应用程序的资产文件夹中,并且根据我对sqlite的有限理解,您可以在android中创建一个文件,但不能只将文件包含在资产文件夹中,然后读取它。也就是说,我是否应该使用其他类型的文件,或者我对 sqlite 的看法是错误的,或者 .properties 文件使用是否正确?
I have created an android app that calculates the numerical values of word, and gives you a list of other words with the same numerical value. The way I have been doing it, is storring the words and value in a .properties file. Ie. A line from a .proprties file called "myWords" will have something like: 61=you, then I just use a get() method to call it,
ie. String myString = ResourseBundle.get("myWords").get("61"); would return the string "you". Is there a better way to do this? My guess is that this is not the proper use of a .properties file, and I was wondering if there was another way to do this correctly. I want to include the file in assets folder of the app, and from my limited understanding of sqlite, you can create a file within android, but you can't just include a file in the assets folder, and then read it. So that said, is there some other type of file that I should use, or was I wrong about sqlite, or is the .properties file being used correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SQLite 是您的最佳选择,也是在 Android 手机上处理数据的最佳方式,这就是 Google 最初将其捆绑在 Android 上的原因,以避免人们处理文件的痛苦。
如果您遵循此教程,他们将向您展示如何在计算机中创建数据库,然后将其加载到“资产”文件夹中并从 Android 应用程序访问它。
希望有帮助!
SQLite is your best bet and is the best way to handle your data on an Android phone, that is why Google bundled it on Android in the first place, to avoid people the pain of dealing with files.
If you follow this Tutorial they will show you how to create your database in your computer and then load it up on your "assets" folder and access it from your Android application.
Hope that helps!
您可以使用 csv 文件,每次应用程序启动时或仅在安装后从资产文件夹中读取一次,然后将值存储在数据库中。
看看我在这里关于如何读取应用程序中包含的文件的答案(您可以使用 csv 文件而不是库,但它仍在读取文件): 在 Android 应用程序中托管可执行文件
编辑:这是从资产中读取的另一个示例文件夹: 从 android 应用程序空间上传的图像似乎已损坏
You can use a csv file, read it from the assets folder each time the app starts or only once after installation and then store the values in a database.
Take a look at my answer here on how to read the files included in your app (you would use a csv file instead of a libray, but it's still reading files): Hosting an executable within Android application
Edit: here's another example to read from the assets folder: Image uploaded from the android app space seems corrupted
您可以尝试数据库选项。 这是一个有趣的教程如何预填充数据库然后将其在 APK 中发送。
You can try out database option. Here is an interesting tutorial on how to pre-populate a database and then ship it out in the APK.