Android Basics-File access rights

Source: Internet
Author: User

1.Android is the Linux kernel, so file access is similar to file access permissions in Linux

D rwx rwx rwx

File Type owner group other

File Type D represents a folder,-represents a file, L represents a link

User created by Owner file

Group other users in the same group as the file creator

Other users who are not in the same group as the creator of the file

Each app in Android corresponds to a separate user, different groups of apps are different and can be set to two apps in the same group

2. The following is a demo code that specifies different access rights when creating a file in the current app's private space.

 Packagecom.ithiema.permission;ImportJava.io.FileOutputStream;Importjava.io.IOException;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_main); }    //write the file under data/data/Current app package name/files/directory, MODE_PRIVATE-RW-RW----     Public voidClick1 (View v) {FileOutputStream fos=NULL; Try{fos= Openfileoutput ("Info1.txt", mode_private); Fos.write ("This is Mode_private". GetBytes ()); } Catch(Exception e) {Throw NewRuntimeException (e); }finally{            Try {                if(fos!=NULL) Fos.close (); } Catch(IOException e) {Throw NewRuntimeException (e); }        }    }    //write to file under data/data/Current app package name/files/directory, mode_world_readable (obsolete)-rw-rw-r--     Public voidClick2 (View v) {FileOutputStream fos=NULL; Try{fos= Openfileoutput ("Info2.txt", mode_world_readable); Fos.write ("This is mode_world_readable". GetBytes ()); } Catch(Exception e) {Throw NewRuntimeException (e); }finally{            Try {                if(fos!=NULL) Fos.close (); } Catch(IOException e) {Throw NewRuntimeException (e); }        }    }    //write to file under data/data/Current app package name/files/directory, mode_world_readable| Mode_world_writeable (OBSOLETE)-rw-rw-rw-     Public voidClick3 (View v) {FileOutputStream fos=NULL; Try{fos= Openfileoutput ("Info3.txt", mode_world_readable|mode_world_writeable); Fos.write ("This is mode_world_readable| Mode_world_writeable ". GetBytes ()); } Catch(Exception e) {Throw NewRuntimeException (e); }finally{            Try {                if(fos!=NULL) Fos.close (); } Catch(IOException e) {Throw NewRuntimeException (e); }        }    }}

Android Basics-File access rights

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.