This example describes the way to read and write private files in Android programming. Share to everyone for your reference, specific as follows:
A private file is a file that the program itself can read, and other programs do not have permission to access, which is saved in the Data.app. Package. File directory.
The method of writing a file is simpler:
private void WriteFile (string filename, string info) {
try {
FileOutputStream fout = openfileoutput (filename, MOD E_private);
byte[] bytes = Info.getbytes ();
Fout.write (bytes);
Fout.close ();
} catch (Exception err) {
}
}
This completes the writing of the private file, using the Openfileoutput file when writing a private file.
The private file is written above, and the private file is read below:
private string ReadFile (string filename) {
try {
fileinputstream fin = openfileinput (fileName);
int length = fin.available ()//Get file length
byte[] bytes = new Byte[length];
Fin.read (bytes);
Return encodingutils.getstring (bytes, ENCODING);
} catch (Exception err) {return
"";
}
}
Use "Openfileinput" to read private files!
For more information on Android-related content readers can view the site: "Android file Operation tips Summary", "Android Resource Operation skills Summary", "Android operation XML Data Skills summary", " The activity of Android programming skills summary, "Android operation SQLite Database Skills Summary", "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", " Android programming development of the SD card operating methods summary, "Android Development introduction and Advanced Course", "Android View Overview" and "Android Control usage Summary"
I hope this article will help you with the Android program.