Read and Write File data stored internally

Source: Internet
Author: User

Write/read the xxx.txt file under the Data/data/package directory.

 

1/** read/write the file data stored internally */2 findviewbyid (R. id. btnwrite ). setonclicklistener (3 new view. onclicklistener () {4 @ override 5 Public void onclick (view v) {6 try {7 fileoutputstream FAS = openfileoutput ("text", 8 context. mode_private); 9 outputstreamwriter ASW = new outputstreamwriter (10 Fas, "UTF-8"); 11 ASW. write (ET. gettext (). tostring (); 12 ASW. flush (); 13 FAS. flush (); 14 ASW. close (); 15 FAS. close (); 16 toast. Maketext (getapplicationcontext (), "write complete. ", 17 toast. length_short ). show (); 18} catch (filenotfoundexception e) {19 E. printstacktrace (); 20} catch (unsupportedencodingexception e) {21 E. printstacktrace (); 22} 23} 24}); 25 findviewbyid (R. id. btnread ). setonclicklistener (26 new view. onclicklistener () {27 @ override28 public void onclick (view v) {29 try {30 fileinputstream ISI = openfileinput ("text"); 31 inputstreamreader is = new inputstreamreader (FCM, 32 "UTF-8"); 33 char input [] = new char [FCM. available ()]; 34 is. read (input); 35 is. close (); 36. close (); 37 string readed = new string (input); 38 show. settext (readed); 39} catch (filenotfoundexception e) {40 E. printstacktrace (); 41} catch (ioexception e) {42 E. printstacktrace (); 43} 44} 45 });

 

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.