Save the file
public static Boolean Saveuserinfo (context context, string Username, string password) {try{//defines a file path object. E (Context.getfilesdir (), "info.txt");//defines the write stream object for a file FileOutputStream fos = new FileOutputStream (file);// Write the data to the file with the write stream object Fos.write ((username + "# #" + password). GetBytes ());//write stream for closed file Fos.close (); return true;} catch (Exception e) {e.printstacktrace (); return false;}}
Read the file
public static map<string, string> Getsaveduserinfo (context context) {try{//defines a file path object. Context.getfilesdir (), "info.txt");//define a read stream object for a file Fisfileinputstream fis = new FileInputStream (file);// A read stream object that defines a character brbufferedreader br = new BufferedReader (FIS);//reads a row of data in a text file string = Br.readline ();//Use the Split method style string to save the split string data to a string array string[] Infos = String.Split ("# #");//define a map collection, Used to save the segmented string array information map<string, string> map = new hashmap<string, string> (), Map.put ("username", infos[0]); Map.put ("Password", infos[1]); return map;} catch (Exception e) {e.printstacktrace (); return null;}}