File
An application can use Android's filesystem to store and retrieve data as well. The java.io
package provides this functionality. This package provides classes to write and read different data types from a file. By default, files created by applications are private to the application and cannot be accessed by other applications. Files persist reboots and application crashes; they are only removed when the application is uninstalled.
Creating a file
The following code snippet shows how to create a file. As I have said before, by default, all files are private to the application.
FileOutputStream fOut = openFileOutput("MyFile.txt", MODE_WORLD_READABLE);
The file MyFile.txt
will be created in the /data/data/<application-path>/files/
directory. The preceding file is created as MODE_WORLD_READABLE
, that means that other applications can read this file. The other options are MODE_WORLD_READABLE
, MODE_PRIVATE
, and MODE_APPEND
that let other applications write to the file, keep it private...