Android data Storage (2): Internal Storage

Source: Internet
Author: User

 The second form of Android data storage is internal Storage, which is internal storage.

Memory storage is characterized by the storage of private data, its storage location is in the phone memory, one is the normal file storage, the other is the text or picture in the memory cache.

  storage location of internal cache/data/data/package name/files or/data/data/package name/cache

1. Create and write a private file to the internal storage:

    Steps:

1) Call the openfileoutput() method and return a FileOutputStream object

2) calling the file stream's write () method, writing the data

3) Close the associated stream

eg

    

2.read a file from internal storage

  Steps:

1) Call the Openinputstream() method and return a FileInputStream object

2) Call the Read () method of the file stream, reading the data

3) Close the associated stream

eg

    

  

  Note: In Java file storage, we typically pass a similar fileinputstream FIS = new FileInputStream (String name) or fileoutstream fos = new FileOutputStream (file file) or FileOutputStream (), but in Android, the system provides us with two very convenient methods Openfileinputstream (), The Openfileoutputstream () method allows us to store internally.

3. Extension: read the/src/raw file under Android Engineering, use the system-provided Openrawresource() to return a InputStream object, however we cannot perform write operations to the file .

Resources res = getresources ();

   

  

Some useful methods provided by the 4.Android system are:

    

5. The cache directory of text or picture in the interior.

Characteristics:

1) Internal buffer cache directory, the Android system will automatically empty the cache directory files when the phone internal storage is full.

2) The cached directory takes precedence over the memory card for storage, because the space is larger, and if there is no memory card, the internal cache space is used.

3) Android system on the memory card, also created a set of application private cache folder.

4) Context. Getexternalcachedir (),

Get the cache directory of the application private in the memory card

5) Context. Getcachedir (),

Gets the cache directory of the application private in the phone's internal storage.

eg

      

    

Open File Explore View:

      

Export the file to view the content:

      

Extension: There is a lot of content about the cache, the level three cache, image clipping, sampling, external cache of images, storage, and so on.

not finished, to be continued.

Android data Storage (2): Internal 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.