Reputation: 11
I'm new to Android, but do have some expreience with Java. For my application I have to use a text file which I have decided to acces from the internal storage using the following code:
String functFileName = "nameOfMyFile";
OutputStream output = openFileOutput(functFileName, Context.MODE_APPEND);
As far as i understood, this means that my application creates a file with the name nameOfMyFile.txt in the internal storage memory, or opens it, if it already exists. Once the file has been created, it will remain stored until the app is deleted. (Please correct me if I got it wrong)
My question is: Is it possible, that a file with that name has already been created by another application, which in this case would ruin my programm? In other words: Can I be sure that my app doesn't access another file, which accidentally has the same name, than creating one of itself?
Sorry if this question isn't very professional. I'd be grateful for any help.
Upvotes: 1
Views: 178
Reputation: 728
The openFileOutput(String name, int mode)
function documentation says :
Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.
It clearly states that the file created with this function is private to the application that created it, so you can be sure that no other application have access to it, provided that MODE_APPEND
or PRIVATE
were used.
Other two modes MODE_WORLD_READABLE
, MODE_WORLD_WRITEABLE
are dangerous and deprecated in API 17 and make the file available for other apps.
Upvotes: 1