I. Basic Concepts
Copy Code code as follows:
Context Object
private context;
Public Fileservice
{
Super ();
This.context = context;
}
Save File Method
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
① can only be created by the current application access to this file
② creates a file if it does not exist, overwriting the original file if the file is created
context.mode_private = 0;
Append mode
① Private.
② creates a file if it does not exist; Append at the end of file if file exists
Context.mode_append = 32768;
Readable mode
Files created by ① can be read by other applications
context.mode_world_readable=1;
Writable mode
① allows other applications to write to it.
context.mode_world_writeable=2
second, the combination of use
Copy Code code as follows:
FileOutputStream OutStream = this.openfileoutput ("Xy.txt", Context.mode_world_readable+context.mode_world_ writeable);
Allow other applications to read and write, and override by default
Copy Code code as follows:
FileOutputStream OutStream = this.openfileoutput ("Xy.txt", context.mode_append+context.mode_world_readable+ context.mode_world_writeable);
Append mode, but allows other applications to read and write