Android Development Series (VI): Operating mode of files in Android apps

Source: Internet
Author: User

Private mode of operation:

1. Can only be accessed by the app that created this file

2. If the file does not exist, it will create the file, if it exists, it will overwrite the original file.

3, Context.mode_private

public void Save (string filename, string content) throws Exception {//Private mode of operation: The file created can only be accessed by the app and cannot be accessed by other apps. In addition, a file created with private operation mode overwrites the contents of the source file with the contents of the FileOutputStream OutStream = Context.openfileoutput (filename,context.mode_ PRIVATE); Open output Stream Outstream.write (Content.getbytes ()) with private operation mode; Outstream.close ();}

Append mode:

1, private, can only be accessed by the application that created this file

2, if the file does not exist, it will create a file, if the file already exists, it will overwrite the original file

3, Context.mode_append;

public void Saveappend (string filename, string content) throws Exception {FileOutputStream OutStream = Context.openfileou Tput (Filename,context.mode_append); Outstream.write (Content.getbytes ()); Outstream.close ();}


readable mode:

1. Files created can be read by other applications

2, context.mode_world_readable;

public void savereadable (string filename, string content) throws Exception {FileOutputStream OutStream = Context.openfile Output (filename,context.mode_world_readable); Outstream.write (Content.getbytes ()); Outstream.close ();}


Writable mode:

1. Files created can be written by other applications

2, Context.mode_world_readable

public void savewriteable (string filename, string content) throws Exception {FileOutputStream OutStream = Context.openfil Eoutput (filename,context.mode_world_writeable); Outstream.write (Content.getbytes ()); OutStream.close ();}


both written and readable blending modes:

1. Allow other applications to read and write, and overwrite : context.mode_world_readable+context.mode_world_writeable

public void savewriteable (string filename, string content) throws Exception {FileOutputStream OutStream = Context.openfil Eoutput (filename,context.mode_world_readable+context.mode_world_writeable);  Outstream.write (Content.getbytes ()); Outstream.close ();}


2.allow other applications to read and write, and append: context.mode_append+context.mode_world_readable+context.mode_world_writeable

public void savewriteable (string filename, string content) throws Exception {FileOutputStream OutStream = Context.openfil Eoutput (filename,context.mode_append+context.mode_world_readable+context.mode_world_writeable);  Outstream.write (Content.getbytes ()); Outstream.close ();}






Android Development Series (VI): Operating mode of files in Android apps

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.