日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android下创建文件夹和修改其权限的方法

發(fā)布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android下创建文件夹和修改其权限的方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

原文:http://www.cnblogs.com/wanqieddy/archive/2011/12/28/2304906.html

由于工作的需要,今天研究了在android下創(chuàng)建文件夾和修改其權限的方法,需要了解的是每個應用程序包都會有一個私有的存儲數(shù)據(jù)的目錄(類似文件夾),只有屬于該包的應用程序才能寫入該目錄空間,每個包應用程序的私有數(shù)據(jù)目錄位 于Android絕對路徑/data/data/<包名>/目錄中。除了私有數(shù)據(jù)目錄應用程序還擁有/sdcard目錄(即SD Card的寫入權限,但不可以修改sd card下文件的訪問權限)。文件系統(tǒng)中其他系統(tǒng)目錄,第三方應用程序是不可寫入的。

?????? 代碼如下兩種:

1、

//創(chuàng)建文件夾

File destDir = new File(“/data/data/[your path]/temp”);
??if (!destDir.exists()) {
???destDir.mkdirs();
??}

//修改權限

?FileOutputStream?fos;???

?fos?=?openFileOutput("filename"?,?MODE_WORLD_READABLE);??


?

備注:可用的mode 參數(shù)如下:

??? /**
???? * File creation mode: the default mode, where the created file can only
???? * be accessed by the calling application (or all applications sharing the
???? * same user ID).
???? * @see #MODE_WORLD_READABLE
???? * @see #MODE_WORLD_WRITEABLE
???? */
??? public static final int MODE_PRIVATE = 0x0000;
??? /**
???? * File creation mode: allow all other applications to have read access
???? * to the created file.
???? * @see #MODE_PRIVATE
???? * @see #MODE_WORLD_WRITEABLE
???? */
??? public static final int MODE_WORLD_READABLE = 0x0001;
??? /**
???? * File creation mode: allow all other applications to have write access
???? * to the created file.
???? * @see #MODE_PRIVATE
???? * @see #MODE_WORLD_READABLE
???? */
??? public static final int MODE_WORLD_WRITEABLE = 0x0002;
??? /**
???? * File creation mode: for use with {@link #openFileOutput}, if the file
???? * already exists then write data to the end of the existing file
???? * instead of erasing it.
???? * @see #openFileOutput
???? */
??? public static final int MODE_APPEND = 0x8000;


?

2、

//創(chuàng)建文件夾

File destDir = new File(“/data/data/[your path]/temp”);
??if (!destDir.exists()) {
???destDir.mkdirs();
??}

Process p;
int status;
??? ??? ??? try {
??? ??? ??? ??? p = Runtime.getRuntime().exec("chmod 777 " +??destDir?);
??? ??? ??? ??? status = p.waitFor();???
??? ??? ??? ??? if (status == 0) {????
??? ??? ??? ??????? //chmod succeed???
??? ??? ??? ??? ??? Toast.makeText(this, "chmod succeed", Toast.LENGTH_LONG).show();
??? ??? ??? ??? } else {????
??? ??? ??? ??????? //chmod failed?
??? ??? ??? ??? ??? Toast.makeText(this, "chmod failed", Toast.LENGTH_LONG).show();
??? ??? ??? ??? }??
??? ??? ??? }

?

友情提醒:

如果是在sdcard下插入,最好先判斷sdcard是否插入,代碼如下 //首先判斷sdcard是否插入 String status = Environment.getExternalStorageState();
??if (status.equals(Environment.MEDIA_MOUNTED)) {
???return true;
??} else {
???return false;
??}

轉(zhuǎn)載于:https://www.cnblogs.com/mochaMM/p/5070908.html

總結

以上是生活随笔為你收集整理的android下创建文件夹和修改其权限的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。