1. Store the data in the application's folder and read and write
The context provides two ways to open the I/O for the application folder and create a file if it does not exist
FileInputStream Openfileinputstream (String fileName);
Fileouputstream openfileoutputstream (String filename,int mode);
Mode
1. Mode_append: Append mode storage
2. Mode_private: Private mode storage, other apps cannot access
3. Mode_world_readable: Indicates that the current file can be read by another application
4. Mode_world_writeable: Indicates that the current file can be written by another application
Context provides a way to access application folders
File Getfilesdir (): Gets the absolute path of the folder
String[] FileList (): Gets all the data under the folder
DeleteFile (String fileName): Deletes the specified file under a folder
Instance
Public classNewactivityextendsappcompatactivity {Private Static FinalString filename= "Firstsharedpreference"; @Overrideprotected voidonCreate (@Nullable Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Try{FileOutputStream fos=Openfileoutput (filename,mode_world_writeable); String Str= "I am good at Android"; byte[] bytes =str.getbytes (); Fos.write (Bytes,0, bytes.length); FileInputStream FIS=Openfileinput (FileName); InputStreamReader ISR=NewInputStreamReader (FIS); BufferedReader BR=NewBufferedReader (ISR); String Data= ""; StringBuilder SB=NewStringBuilder (); while(data = Br.readline ())! =NULL) {sb.append (data); } } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } }}
Store, read--android application built-in folders