Common data storage and access methods:
File
SharedPreferences (preference parameter settings)
SQLite Database
Content provider)
Network
Activity (Context)
The Context. getCacheDir () method is used to obtain/data/<package name>/cache directory.
The Context. getFilesDir () method is used to obtain the/data/<package name>/files directory.
Activity (Context) provides the openFileOutput (filename, mode) method for outputting data to a file;
The first parameter is used to specify the file name and cannot contain the path separator '/'
The second parameter is the operation mode:
Context. MODE_PRIVATE: the files created in private operation mode can only be accessed by this program. If the file does not exist, it is automatically created. In addition, the content written to the file overwrites the content of the original file;
Context. MODE_APPEND: the mode checks whether the file exists. If yes, content is appended; otherwise, a new file is created;
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 other applications;
If you want the file to be read and written by other applications: Pass in (Context. MODE_READABLE + Context. MODE_WRITEABLE)
FileOutputStream outStream = context. openFileOutput (filename, Context. MODE_PRIVATE );
// Param file name, Operation Method
Androidhas a set of security models. When the application program (.apk) is installed, the system will assign a userid. When the application accesses other resources, such as files, it will match the userid. By default, any files created by the application will be created, sharedpreferences, the database is private (the created files are stored in the/data/<package name>/files directory ), only when the specified operation mode is external readable or write can it be accessed by other programs;
Read files:
<1>
FileInputStream inStream = context. openFileInput (filename );
Log. I (TAG, inStream ....)
<2>
Path = "/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