Enterprise-level Android Reading Notes (III)

Source: Internet
Author: User

Data Storage types in Android include memory, common files, shared preferences, XML, and sqllite.

File Operations:

Including read/write

/*** [File operation] */package iwit. iwittest; import Java. io. fileinputstream; import Java. io. fileoutputstream; import Java. io. ioexception; import Java. io. inputstreamreader; import Java. io. outputstreamwriter; import android. content. context; import android. widget. toast;/*** @ author shine * [file read, write] */public class fileoperate {/*** [Read File] * @ Param context * @ Param filename * @ return */Public String readtext (context, string filename) {fileinputstream fin = NULL; inputstreamreader ISR = NULL; char [] inputbuffer = new char [0, 255]; string data = NULL; try {fin = context. openfileinput (filename); ISR = new inputstreamreader (FIN); ISR. read (inputbuffer); Data = new string (inputbuffer); toast. maketext (context, "Read succeed", toast. length_short ). show ();} catch (exception e) {e. printstacktrace (); toast. maketext (context, "not read", toast. length_short ). show () ;}finally {try {ISR. close (); Fin. close ();} catch (ioexception e) {e. printstacktrace () ;}} return data;}/*** [Write File] * @ Param context * @ Param filename * @ Param data */Public void writetext (context, string filename, string data) {fileoutputstream fout = NULL; outputstreamwriter OSW = NULL; try {fout = context. openfileoutput (filename, 1); OSW = new outputstreamwriter (fout); OSW. write (data); OSW. flush (); toast. maketext (context, "saved", toast. length_short ). show ();} catch (exception e) {e. printstacktrace (); toast. maketext (context, "not saved", toast. length_short ). show () ;}finally {try {OSW. close (); fout. close ();} catch (ioexception e) {e. printstacktrace ();}}}}

For details about how to operate sdcard on Android, see

Http://www.ylmf.net/zhuanti/zt02/2010/1130/12389.html

The next step is to share the parameter operation, which is suitable for storing some configuration information to this location and storing a small amount of data.

Http://www.cnblogs.com/over140/archive/2011/01/13/1934301.html

Detailed introduction

Next, perform sqllite operations on Android,

Http://www.cnblogs.com/TerryBlog/archive/2010/06/12/1757166.html

Even the examples are available. You can test them.

Then the content provides the visitor contentprovider

It mainly uses multipleProgramProvides an externally accessible interface through a uniform Uri.

Http://www.cnblogs.com/linzheng/archive/2011/01/22/1942101.html

Related Article

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.