Android Development file operating mode deep understanding of _android

Source: Internet
Author: User
Tags save file
I. Basic Concepts
Copy Code code as follows:

Context Object
private context;
Public Fileservice
{
Super ();
This.context = context;
}
Save File Method
public void Save (string filename, String filecontent) throws Exception
{
FileOutputStream fos = context.openfileoutput (filename, context.) Mode_private);
Fos.write (Filecontent.getbytes ("UTF-8"));
Fos.close ();
}

Private Mode
① can only be created by the current application access to this file
② creates a file if it does not exist, overwriting the original file if the file is created
context.mode_private = 0;
Append mode
① Private.
② creates a file if it does not exist; Append at the end of file if file exists
Context.mode_append = 32768;
Readable mode
Files created by ① can be read by other applications
context.mode_world_readable=1;
Writable mode
① allows other applications to write to it.
context.mode_world_writeable=2
second, the combination of use
Copy Code code as follows:

FileOutputStream OutStream = this.openfileoutput ("Xy.txt", Context.mode_world_readable+context.mode_world_ writeable);

Allow other applications to read and write, and override by default
Copy Code code as follows:

FileOutputStream OutStream = this.openfileoutput ("Xy.txt", context.mode_append+context.mode_world_readable+ context.mode_world_writeable);

Append mode, but allows other applications to read and write
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.