I. Basic Concepts
Copy codeThe Code is as follows: // context object
Private Context context;
Public FileService (Context context)
{
Super ();
This. context = context;
}
// Method for saving the file
Public void save (String filename, String fileContent) throws Exception
{
FileOutputStream fos = context. openFileOutput (filename, context. MODE_PRIVATE );
Fos. write (fileContent. getBytes ("UTF-8 "));
Fos. close ();
}
Private Mode
① It can only be accessed by the current application that created this file
② If the file does not exist, the file will be created. If the file already exists, the original file will be overwritten.
Context. MODE_PRIVATE = 0;
Append Mode
① Private
② If the file does not exist, the file will be created; if the file exists, the content will be appended at the end of the file.
Context. MODE_APPEND = 32768;
Readable Mode
① The created file can be read by other applications.
Context. MODE_WORLD_READABLE = 1;
Writable Mode
① Allow other applications to write data to it.
Context. MODE_WORLD_WRITEABLE = 2
Ii. Combined Use Copy codeThe Code is as follows: FileOutputStream outStream = this. openFileOutput ("xy.txt", Context. MODE_WORLD_READABLE + Context. MODE_WORLD_WRITEABLE );
Allow other applications to read and write, and overwrite by defaultCopy codeThe Code is as follows: FileOutputStream outStream = this. openFileOutput ("xy.txt", Context. MODE_APPEND + Context. MODE_WORLD_READABLE + Context. MODE_WORLD_WRITEABLE );
Append mode, but allow other applications to read and write