File storage method of Android data storage

File storage is the most basic data storage method in Android. It does not format the stored content, and all data is saved to the file intact.

summary

The core of file access is input stream and output stream.

Operating mode of Android files

Implementation of file reading and writing

Openfileoutput and openfileinput methods

File storage location

/Data / data / < package name > / files directory

Openfileoutput and openfileinput methods can obtain the OutputStream and InputStream objects of operating files, and can process the data of any file through the stream object. However, like SharedPreferences, these two methods can only create files in the specified directory of the mobile phone memory card, so they still have certain limitations in use.

Read files on SD card

Next, let's write an SD operation class: sdfilehelper Java

Then mainactivity Java implementation related logic:

Finally, don't forget the Android manifest XML write the permission to read and write SD card!

How to judge between virtual and physical SDKs

By default, part of the storage space is allocated to the virtual SD card (part is used to install the Android operating system)

Return true: the SD card is physical, whereas the SD card is virtual.

It is used to adapt to different models of mobile phones and obtain the path and status of SD card through reflection

Read the files in the raw and assets folders

I believe you are not unfamiliar with the two folders. If we don't want our files to be compiled into binary files, we can put the files in these two directories, and the differences between the two are as follows:

Read file resources:

res/raw:

assets:

The Sax engine reads the XML file

How Sax engine reads XML files:

Sax technology does not load the XML file into memory at one time, but reads and parses the XML file at the same time.

Using Sax to process XML requires a handler object, usually org. XML xml. sax. helpers. Subclass of defaulthandler as handler object

Therefore, the following five analysis points, also known as analysis events, need to be processed:

Code

res\raw\product. xml

Product. java

XML2Product. Java (defaulthandler subclass)

Defaulthandler subclass, core class, is responsible for processing analysis point events.

Xml2JavaObjectAct

design sketch

Code

activity_ jar_ zip. xml

JarZipAct

Original link: http://blog.csdn.net/yangshangwei/article/details/50831269

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>