Jock Stiff
Jock Stiff

Reputation: 79

Writing Files to App Directory - NOT SDCARD

Okay, so im having a bit of trouble here. Ive done some Googling but really havent gotten a clear answer.

You see, I have a file (with no extension) in my "raw" folder in my project. This file is needed for my apps to write a couple of settings and notes. Id prefer to use something like this just to be extra safe.

The problem is, there is no guide that tells me how to write to my own files. There is a good amount of guides on how to write files to the SDCard but I dont like that because if a user has problems with the SDcard, it could affect my app.

Also, one thing about writing to the SDcard is making the file "MODE_WORLD_READABLE" since if anything hits the SDCard, anyone can read it. This is something I do not want to happen. On top of that, if the user mounts the USB by using USB mass storage or removes/changes the SDcard, the file is lost.

How could i go on from making my app read/write on its own directory?

Thanks!

Upvotes: 2

Views: 4326

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006614

The problem is, there is no guide that tells me how to write to my own files.

Sure there is: http://developer.android.com/guide/topics/data/data-storage.html

There is a good amount of guides on how to write files to the SDCard

No, there "is a good amount of guides on how to write files" to external storage, which may or may not be an "SDCard" depending on the device.

How could i go on from making my app read/write on its own directory?

To get at a file on internal storage, you have two major options:

  1. Use openFileInput() and openFileOutput() to get an InputStream and OutputStream on a file in the root of your internal storage, respectively

  2. Use getFilesDir() to get a File object pointing to the root of your internal storage, from which you can create subdirectories, create streams and readers for input and output, etc.

From there, it is standard Java file I/O.

Upvotes: 2

Related Questions