1 Public classMainactivity extends Activity {2 3Final String file_name ="Crazyit.bin";4 5 @Override6 protected voidonCreate (Bundle savedinstancestate) {7 super.oncreate (savedinstancestate);8 Setcontentview (r.layout.activity_main);9 TenFinal EditText Et1 =(EditText) Findviewbyid (R.ID.EDT1); OneFinal EditText Et2 =(EditText) Findviewbyid (R.ID.EDT2); A -Button Btnwrite =(Button) Findviewbyid (r.id.btnin); -Btnwrite.setonclicklistener (NewOnclicklistener () { the - @Override - Public voidOnClick (View v) { - Write (Et1.gettext (). toString ()); +Et1.settext (""); - } + }); AButton Btnread =(Button) Findviewbyid (r.id.btnout); atBtnread.setonclicklistener (NewOnclicklistener () { - - @Override - Public voidOnClick (View v) { - Et2.settext (read ()); - } in }); - to } + - /** the * Write to/data/data/[package name]/files path * * $ * @param contentPanax Notoginseng */ - Private voidWrite (String content) { the Try { +FileOutputStream fos =openfileoutput (file_name, context.mode_append); APrintStream PS =NewPrintStream (FOS); the ps.println (content); + ps.close (); - $}Catch(FileNotFoundException e) { $ e.printstacktrace (); - } - } the - /**Wuyi */data/data/[Package name]/files path Read File the * - * @return Wu */ - PrivateString Read () { About Try { $ -FileInputStream FIS =Openfileinput (file_name); - byte[] Buff =New byte[1024x768]; - intHasread =0; AStringBuilder SB =NewStringBuilder (""); + while((Hasread = Fis.read (buff)) >0) { theSb.append (NewString (Buff,0, Hasread)); - } $ fis.close (); the returnsb.tostring (); the the}Catch(FileNotFoundException e) { the e.printstacktrace (); -}Catch(IOException e) { in e.printstacktrace (); the } the About return NULL; the } the the}
Android App internal file path