IOException异常:权限被拒绝 [英] IOException: Permission Denied

查看:249
本文介绍了IOException异常:权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个文件到Android的外部存储。
在AndroidManifest.xml中我添加(清单标签内)

I am trying to write a file to the external storage of the android. On the AndroidManifest.xml I've added (within the manifest tag)

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

然后我尝试:

File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
file.createNewFile();

然后,我得到的异常。
我如何可以解决此问题?

And then I get the exception. How may I resolve this?

推荐答案

请确保你的SD卡未安装到您的计算机。如果已启用USB存储,SD卡成为Android的只读。

Make sure your SD card is not mounted to your computer. If you have enabled USB storage, your SD card becomes read-only for Android.

其他然后,您的应用程序看起来很好,应该工作。

Other then that, your application looks fine and should work.

哦,我会修改你的code在下一方式:

Oh, and I would modify your code in a next way:

if(root.canWrite()){
    File file = new File(root, "file.xml");         
    file.createNewFile();
}

这篇关于IOException异常:权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆