Method of storing data with file in Android
This example shares the specific code of Android using files to store data for your reference. The specific contents are as follows
Examples of stored data:
Read data from file:
be careful:
1. The openfileoutput () method has two parameters: the first is the file name, which may not include the path, because the file will be stored in the data / data / package name / files directory by default. The second is the operation mode, generally mode_ Private, which means that repeated calls will overwrite the contents of this file. And mode_ Append means to add content to the file. If the file does not exist, the file will be created.
2. Openfileinput() has only one parameter, that is, the file name of the data to be read.
3. The file storage method is not suitable for saving complex text data, but only simple text or binary data.
4. Try / catch must be added to catch exceptions, otherwise an error will be reported and cannot be compiled.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.