Reputation: 1929
I trying to write some files on the internal storage.
I saw theFileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
on Data Storage and I understood that the file will be private to my application.
but the problem is it can only open a file without a path, so first I opened a new directory file with file.mkdir(), but now, how do I write the file as private ?
Upvotes: 3
Views: 10010
Reputation: 247
If you call Context.openFileOutput() the file will always be written into your application's data directory (i.e. "/data/data/appname/filename"). You cannot use sub folders here! The documentation for this function says
nameThe name of the file to open; can not contain path separators.
Upvotes: 1
Reputation: 1006644
I saw theFileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); on Data Storage and I understood that the file will be private to my application.
Correct. They will be private by default.
but the problem is it can only open a file without a path, so first I opened a new directory file with file.mkdir(), but now, how do I write the file as private ?
Your files that you create in subdirectories off of in getFilesDir()
are private by default -- you do not have to do anything special to make them be private.
Upvotes: 8