Android_02 _ file access permission (to be updated)
Preface:
Open File Explorer and you will see:
Meaning of 10 letters:
Drwxrwxrwx
First letter:
* D: folder
*-: Indicates a file.
Group 1 rwx: indicates the file owner's permissions on the file.
* R: read, read
* W: write
* X: execute
Group 2 rwx: indicates the file permissions granted to users (grouper) in the same user group as the file owner.
Group 3 rwx: Permission of other users (other) on files
In Android, every application is an independent user and does not belong to the same user group,
However, you can set the application to belong to the same user group. (I will give a detailed summary of how to set it later)
The code example of file access permission is as follows:
Package com. itheima. permission; import java. io. file; import java. io. fileNotFoundException; import java. io. fileOutputStream; import android. OS. bundle; import android. annotation. suppressLint; import android. app. activity; import android. view. menu; import android. view. view; @ SuppressLint (WorldReadableFiles) public class MainActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main);} public void click1 (View v) {// The default path is data/com. itheima. permission/filestry {FileOutputStream fos = openFileOutput(info1.txt, MODE_PRIVATE); fos. write (hahaha. getBytes (); fos. close ();} catch (Exception e) {// TODO Auto-generated catch blocke. printStackTrace () ;}} public void click2 (View v) {// The default path is data/com. itheima. permission/filestry {@ SuppressWarnings (deprecation) FileOutputStream fos = openFileOutput(info2.txt, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE); fos. write (ohohoho. getBytes (); fos. close ();} catch (Exception e) {// TODO Auto-generated catch blocke. printStackTrace () ;}} public void click3 (View v) {// The default path is data/com. itheima. permission/filestry {@ SuppressWarnings (deprecation) FileOutputStream fos = openFileOutput(info3.txt, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE); fos. write (demasia. getBytes (); fos. close ();} catch (Exception e) {// TODO Auto-generated catch blocke. printStackTrace ();}}}
The xml file of layout is as follows: