IOException:权限被拒绝
我正在尝试将文件写入 android 的外部存储。 在我添加的 AndroidManifest.xml 上(在清单标记内)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
,然后我尝试了:
File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
file.createNewFile();
然后我得到了异常。 我该如何解决这个问题?
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"/>
then I tried:
File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
file.createNewFile();
And then I get the exception.
How may I resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您的 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:
您是否在清单中设置了权限?
您也可以将“root”替换为您获取目录的调用,而不是声明它。 xmlFilename 的值是多少?
Do you have the permissions set in the manifest?
You can also just replace "root" with your call to get the directory rather than declaring it. What is the value of xmlFilename?
确保您拥有写入该文件的正确权限。在您的清单文件中,包含此行
Ensure you have the correct permissions to write to the file. In your manifest file, include this line