I. Overview of File saving
1. Seat of the file preservation
/data/data/<packagename>/files
2. Method of file operation
Openfileinput ()
Openfileoutput ()
DeleteFile ()
FileList () ....
Two. Create and write files in default table
1. Get an output stream FileOutputStream object
Openfileoutput ("MyFile.txt", context.mode_private);
Streams in Java have to specify the output path, but in Android, Openfileoutput is not, and this is a handy place for Android. The default path will be used, as above.
2. Write data to the stream
Write (Data.getbytes ());
Because in 1 we get the FileOutputStream byte stream, which can only be written in bytes. So we're going to turn the data (string) into a byte class,
Of course, we can also use OutputStreamWriter to turn it into a character stream and then manipulate it.
3.close Flow
Fos.close ()
Three. read files in default location
1. Create an input stream
FileInputStream fis; input byte throttling
InputStreamReader ISR; character streams
BufferedReader BR; Buffered stream that can be read over a section
FIS = openfileinput ("MyFile.txt");
ISR =new InputStreamReader (FIS);
br = new BufferedReader (ISR);
2. Reading data
We can use ReadLine here ()
String str =null;
STR =br.readline ();
3. Close the Stream
Fis.close ();
Isr.close ();
Br.close ();