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

查看:139
本文介绍了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.

我将以另一种方式修改代码:

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天全站免登陆