創(chuàng)建生成幾個權限的文件應用
- 新建四個按鈕
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="private"
android:onClick="click1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="append"
android:onClick="click2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="read"
android:onClick="click3"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="write"
android:onClick="click4"
/>
- 實現(xiàn)方法
/**
* 點擊按鈕生成一個私有的文件
*
* @param view
*/
public void click1(View view) {
try {
FileOutputStream fos = openFileOutput("private.txt", MODE_PRIVATE);
fos.write("private".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 點擊按鈕生成一個append文件
*
* @param view
*/
public void click2(View view) {
try {
FileOutputStream fos = openFileOutput("append.txt", MODE_APPEND);
fos.write("append".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 點擊按鈕生成一個可讀的文件
*
* @param view
*/
public void click3(View view) {
try {
FileOutputStream fos = openFileOutput("read.txt", MODE_WORLD_READABLE);
fos.write("read".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 點擊按鈕生成一個可寫的文件
*
* @param view
*/
public void click4(View view) {
try {
FileOutputStream fos = openFileOutput("wirte.txt", MODE_WORLD_WRITEABLE);
fos.write("write".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
-
生成 的文件如圖
安卓文件截圖.png -
權限解釋
十位權限圖.png
r: 可讀
w: 可寫
x: 可執(zhí)行
-
修改文件的權限 使用linux下一個指令(chmod)
進入shell
切換到files目錄.png
文件權限對應二進制.png
讓所有用戶對private.txt具有可讀可寫可執(zhí)行的權限
權限修改.png
權限修改完成.png