开发者

Android writing to a text file

I have a text file within my raw folder of my app that I intend to use as a simple way to save settings and then read them back when needed. I can read from this file with using the BufferedReader and what comes with it, but I've tried a few different ways to be able to write to this file and none seem to work.

It seems to me that the problem is I never actually get the file, and I assume this is simply because I don't exactly know how I am supposed to give it the correct directory and file name. I've tried all I could come up with, and I tend to get errors like "No such file or d开发者_JAVA技巧irectory exists" or "Read-only file system".

This seems to be a very simple problem relating to me just giving the wrong information, so if anybody could point me in the right direction it would be much appreciated.

Thank you, Raphy


For saving settings you should use SharedPreferences rather than coming up with a custom solution.

  • SharedPreferences documentation
  • Data Storage


I'm not entirely sure you can do that with stuff in the "raw" folder.

One approach would be to use the SharedPreference storage in the API. See in the datastorage section of the docs. It's perfect from what you describe neededing. Another approach would be to put the file on the SDCard and read and write it from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜