Openfileoutput and Openfileinput get the files in the phone's memory instead of the SD card.
The context provides two ways to open the file I/O stream in the Data folder of this application.
Openfileinput (String name): the input stream corresponding to the name file
Openfileoutput (String name,int mode): the output stream corresponding to the name file
The second parameter in the output stream represents the mode in which the file is opened, or it can be called a permission:
Mode_private: The file can only be read and written by the current program
Mode_append: Open the file as an append, you can append the content
Mode_world_readable: The contents of this file can be read by other programs
Mode_world_writeable: The contents of this file can be read and written by other programs.
In addition to this, the context provides several ways to access the application's Data folder:
Getdir (String name,int mode): Gets or creates a subdirectory of name in the application's Data folder
File Getfilesdir (): Gets the absolute path of the application's Data folder
String[] FileList (): Returns all files under the Data folder of the application
DeleteFile (String): Deletes the specified file under the Data folder of the application
public class Mainactivity extends Activity {private EditText et;private Button Savebutton, Readbutton;private TextView Sho W;private Boolean mywrite () {try {FileOutputStream fos = openfileoutput ("Data", context.mode_world_readable); String content = Et.gettext (). toString (); Fos.write (Content.getbytes ()); Fos.flush (); Fos.close (); Toast.maketext (Mainactivity.this, "Success", 1). Show (); return true;} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} return false;} Private Boolean Myread () {try {FileInputStream FIS = openfileinput ("Data"); byte buff[] = new byte[1024]; StringBuffer sb = new StringBuffer (), int hasread = 0;while ((hasread = Fis.read (buff))! =-1) {Sb.append (new String (buff)) ;} Fis.close (); Show.settext (sb.tostring ()); Toast.maketext (Mainactivity.this, Sb.tostring (), 1). Show (); return true;} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} return false;} protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); setContentview (r.layout.activity_main); et = (EditText) Findviewbyid (r.id.edittext); Savebutton = (Button) Findviewbyid ( R.id.save) Readbutton = (Button) Findviewbyid (r.id.red); show = (TextView) Findviewbyid (r.id.show); Savebutton.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated Method Stubmywrite ();}}); Readbutton.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated Method Stubmyread ();}});}}
Android------openfileinput, openfileoutput get data from your phone's memory