How to store files in the Android cache directory?

My goal is to store temporary files in the directory returned by Context # getCacheDir ().

/data/data/my.app/cache/somedir/foo.json 

I suppose I can just use java.io apis to write files there. But I'm not sure how to set permissions on files there, because I could not use Context # MODE_PRIVATE.

The file name parameter for context # openFileOutput and context # openFileInput cannot accept path-delimited input. Thus, they are only useful for files created in a directory:

 /data/data/my.app 
+6
java android mobile
source share
2 answers

Each Android application runs under its own user account by default, so the files created by your application will not be accessible from any other application. Check marker number 3 at the top of this page:

http://developer.android.com/guide/topics/fundamentals.html

You can also verify this by running the shell in your emulator / device and looking at the output of ls -l.

+6
source share

But I'm not sure how to set file permissions there, because I will not be able to use Context # MODE_PRIVATE.

AFAIK, they should be closed by default.

+5
source share

All Articles