2

I'm creating an android app that utilizes a log. I've placed a file entitled "log.txt" in the "Raw" resource folder. I have figured out how to open it to an inputstream using openRawResource, however I am not sure how to open it so I can use PrintWriter with it.

I have also tried accessing a file pre-created on the target device, but have not succeeded.

If someone could explain to me either how to open the resource file to a PrintWriter, i'd appreciate it.

Ethan Kershner
  • 121
  • 3
  • 13

1 Answers1

2

however I am not sure how to open it so I can use PrintWriter with it.

You can't. Resources are read-only at runtime. You are welcome to use that InputStream to write a copy of the resource's contents to a file on the filesystem (e.g., on internal storage), though.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • How can I access the internal resources? I tried this earlier but was unable to. – Ethan Kershner Apr 24 '16 at 23:26
  • @EthanKershner: I do not know what you mean by "the internal resources", or by "access" in this context. You already know about `openRawResource()`. If by "internal resources" you mean internal storage, call `getFilesDir()` on any `Context` to get a `File` object pointing at a directory that you can write to. From there, it is standard Java file I/O. – CommonsWare Apr 24 '16 at 23:27
  • Oh sorry, that's what I meant. Thanks. – Ethan Kershner Apr 24 '16 at 23:30