Android App internal file path

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.