【发布时间】:2012-07-16 02:50:24
【问题描述】:
当我尝试创建新文件时,收到一条错误消息。
代码:
try
{
File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
Runtime.getRuntime().exec("chmod 777 " + root.getAbsolutePath());
File myFile = new File(root,"createNew.txt");
myFile.createNewFile();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
错误信息:
java.io.IOException: open failed: EACCES (Permission denied)
/mnt/sdcard 权限为d---------
如何通过编程更改权限?如何解决。给我任何想法。
提前致谢。
注意这一点:
当我在命令提示符中使用此代码时,文件已成功创建,该代码为:
`chmod 777 /mnt/sdcard`
【问题讨论】:
-
你给
Write_External_storage权限了吗?在您的Manifest.xml中授予此权限 -
我已经添加了这个权限。
-
你是在你的设备或模拟器中尝试这个吗?
-
确保。两者都有 SD 卡存储?
-
File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath());我已经尝试过这个,现在我尝试访问模拟器。
标签: android file permissions