Data storage and access common ways:
File
Sharedpreferences (preference parameter setting)
SQLite database
Contents provider (content Provider)
Internet
Activity (context)
The Context.getcachedir () method is used to get the/data/data/<package Name>/cache directory
The Context.getfilesdir () method is used to get the/data/data/<package name>/files directory
The activity (context) provides a openfileoutput (filename,mode) method for outputting data to a file;
The first parameter is used to specify a file name and cannot contain the path separator '/'
The second parameter is operation mode:
Context.mode_private: Private operation mode created files can only be accessed by this program, if the file does not exist, will be automatically created, in addition: the contents of the written file will overwrite the contents of the original file;
Context.mode_append: Mode checks whether the file exists, appends the content if it exists, or creates a new file;
Context.mode_readable: Indicates that the current file can be read by other applications;
Context.mode_writeable: Indicates that the current file can be written by another application;
If you want the file to be read and written by another application: Incoming (context.mode_readable+context.mode_writeable)
FileOutputStream OutStream = Context.openfileoutput (filename,context.mode_private);
param file name, how to operate
Android has its own security model, and when the application (. apk) is installed, the system is assigned to a userid, and when the application accesses other resources such as files, it is matched UserID, by default, any file created by the application. Sharedpreferences, the database is private (the created file is stored in the/data/data/<package name>/files directory), and only the specified mode of operation is externally readable or writable to be accessible by other programs;
Read file:
<1>
FileInputStream instream = context.openfileinput (filename);
LOG.I (Tag,instream ...)
<2>
Path= "/data/data/<package name>/files/hello.txt";
File File = new file (path);
FileInputStream instream = new FileInputStream (file);
LOG.I (Tag,instream ...)
CTRL + SHIFT + X/Y case