1、如果SDCard已插入,通过 Environment.getExternalStorageDirectory()+"filename.extension" 来写入或读取文件,必须赋予权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
2、如果SDCard未插入,通过 Environment.getDataDirectory()+"/data/"+ContextWrapper.getPackageName()+"filename.extension"来写入或读取文件
(无SDCard,又需要升级程序自身,必须手动赋予LINUX读权限)
例如:
代码
1 Runtime runtime = Runtime.getRuntime();
2 try {
3 Process process = runtime.exec("chmod 666 "+apkFile.getAbsolutePath());
4 process.waitFor();
5 }
6 catch (Exception e) {
7 Log.e(TAG, e.getMessage(), e);
8 }
2 try {
3 Process process = runtime.exec("chmod 666 "+apkFile.getAbsolutePath());
4 process.waitFor();
5 }
6 catch (Exception e) {
7 Log.e(TAG, e.getMessage(), e);
8 }
无法使用此程序段来赋予随意目录的写权限?