Android Development File Save read

Source: Internet
Author: User

Android File save read can be selected in the phone itself storage, external storage such as SD card, this article will be introduced in turn.

1. Save and read files in the phone itself. The layout file is as follows:


As follows:
In the File name box, fill in the file name of the save, the File content box to fill in the Save content, click Save can be saved to the phone itself storage. The Java code is as follows: Mainactivity.java here Getapplicationcontex () Method (life cycle is the entire application, When substituted with Mainactivity.this, the context of the activity is obtained, the activity is destroyed as the activity is destroyed), and the entire application is obtained (context: Program environment information), and the individual indicates that it is still not very To understand what the context is, in Android contextual contexts are an abstract class, activity also inherits from the context class, details can be found in the context of Android, A application contains the number of contexts (context) =activity number of +service + the entire application a separate context. Fileservice.java here a new Fileservice.java file is dedicated to storing read data. In-memory data is stored in the phone's own storage space, so the output stream needs to be used (the input and output stream is relative to memory). The Openfileoutput () function opens a file output stream named name (if the file does not exist, the system is automatically created), mode_private means private, that is, each time the file is opened overwrites the original content, and there are other MODE such as Mode_world _readable means that it can be read by other applications, mode_world_writeable indicate that it can be written by another application, mode_append private (only the application that created the file can use) and add data based on the original content. The Outputstream.wite () function means that the data is written to the stream, and the method Content.getbytes () represents the byte array that gets the contents of the string content under the default encoding of the operating system, GetBytes (Encoding) Represents a byte array that gets the contents of the string under the specified encoding encoding. A file named Luo.text is seen in the Data>data>com.example.callphone>files directory in the File Explorer during the experiment.

File saved for Android development read

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.