當我嘗試創建一個新文件時,我收到一條錯誤消息。文件不會在android中創建?
代碼:
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'中授予此權限 – Praveenkumar 2012-07-17 07:51:28
我已經添加了此權限。 – 2012-07-17 07:52:20
您是否在您的設備或模擬器中嘗試此操作? – Praveenkumar 2012-07-17 07:52:46