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