Summary of reading and writing methods of files in Android mobile phone memory
This paper summarizes the reading and writing methods of files in Android mobile phone memory. Share with you for your reference. The specific analysis is as follows:
How to read and write file data in mobile phone memory?
Context provides a method to open the file I / O stream in the data folder of the application, as follows:
Open the data stream corresponding to the name file under the data folder of the application
Open the output stream corresponding to the name file in the application data folder. Mode specifies the file opening mode. There are four main modes:
①MODE_ Private (this file can only be read and written by the current application) ② mode_ Append ③ mode_ WORLD_ Readable (the contents of this file can be read by other applications) ④ mode_ WORLD_ Writeable (the contents of this file can be written by other applications)
Read file:
Suppose name is the name of the file to open
Get file content string:
Write file:
Suppose the string to be written is content
Note: the data files of the application are saved in the / data / datea < package name > / files directory by default. Use openfileinput and openfileoutput methods to open the file input stream. When outputting the stream, the files in the data folder of the application are opened, that is, the files in the phone memory, not the files in the SD card.
I hope this article will be helpful to your Android program design.