android--persistence technology for file storage

Source: Internet
Author: User

This is my study notes I just will csdn blog as a record of learning where so ...

</pre><span style= "FONT-SIZE:18PX;" >1. Create a FileOutputStream object by using the Openfileoutput () method Out</span><p></p><p><span style= " font-size:18px; " >2. Through the out new one OutputStreamWriter object </span></p><p><span style= "FONT-SIZE:18PX;" >3. By OutputStreamWriter object New one BufferedWriter object Writer</span></p><p><span style= " font-size:18px; " >4. Writing strings to a file by Writer.write (data)  ps:data to String type </span></p><p></p><p>< Pre name= "code" class= "java" ><span style= "font-size:18px;"  >public void Save () {string Datta= "I am a string";  FileOutputStream Out=null;  BufferedWriter Writer=null;    try{out=openfileoutput ("Data", context.mode_private);    Writer=new BufferedWriter (New OutputStreamWriter (out));  Writer.write (data);  }catch (IOException e) {e.printstacktrace ();       }finally{try{if (writer!=null) {writer.close ();     }}catch (IOException e) {e.printstacktrace (); }}}&LT;/span> 

There are two parameters in the Openfileoutput () method. The first file name specified for you. The file name does not include the path (all files are stored by default in the/data/data/<packagename>/files/directory). The second parameter is the operation mode of the file, and there are two optional mode_private and mode_append. Mode_private is the default parameter, which means that when the same file name is specified, the content that is written overwrites the contents of the original file. Mode_append indicates that a new file is created if the file exists to append content to the file.

If we want to store the data in EditText, we first get an instance of EditText in OnCreate (), get the input in EditText in the Ondestory () method, and call the Save () method to store the input to a file.

=============================================================================================================== =====================

Writer must remember close (), or the data will not be stored in the file t_t

May 9, 2016

android--persistence technology for file storage

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.