Android_02 _ file access permission (to be updated)

Source: Internet
Author: User

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:

 

 

 
  
  
  
 


 

 

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.