简体   繁体   English

FIleNotFound打开失败:EACCES(权限被拒绝)

[英]FIleNotFound open failed: EACCES (Permission denied)

I am suffering from an "open failed: EACCES (Permission denied)" on Android when I attempt to write to "/mnt/sdcard/report/". 当我尝试写入“/ mnt / sdcard / report /”时,我在Android上遭遇“开放失败:EACCES(权限被拒绝)”。 My 1st step is to create the "report" folder which doesn't work. 我的第一步是创建“报告”文件夹,该文件夹不起作用。 I then attempt to write which throws the above exception. 然后我尝试编写抛出上述异常的内容。 I have set <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> as a peer (outside of) the application tag. 我已将<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />为应用程序标记的对等项(在...之外)。 I am trying to run a JUnit instrumentation test on the emulator when I get the error. 我正在尝试在出现错误时在模拟器上运行JUnit检测测试。 Any ideas? 有任何想法吗? Code is below. 代码如下。

        if (mReportDir == null) {
            if (mContext.getFilesDir() != null) {
                mOutputStream = mContext.openFileOutput(fileName, 0);
            } else {
                mOutputStream = mTargetContext.openFileOutput(fileName, 0);
            }
        } else {
            File f = new File(mReportDir);
            if (!f.exists()) {
                f.mkdirs();
            }
            mOutputStream = new FileOutputStream(new File(mReportDir, fileName));
        }

mReportDir is equal to "/mnt/sdcard/report", fileName is equal to "junit-report.xml", f.mkdirs returns false I believe and the dir is never created. mReportDir等于“/ mnt / sdcard / report”,fileName等于“junit-report.xml”,f.mkdirs返回false我相信并且永远不会创建dir。 I'm wondering why I get permission denied. 我想知道为什么我被拒绝了。 I'm trying to reuse a custom JUnit Test runner. 我正在尝试重用自定义的JUnit Test运行器。

I've added hw.sdCard= yes to the avd settings. 我在avd设置中添加了hw.sdCard = yes。 After launching I shell in and type mount: 启动I shell后输入mount:

~$ adb shell
# mount
rootfs / rootfs ro 0 0
tmpfs /dev tmpfs rw,nosuid,mode=755 0 0
devpts /dev/pts devpts rw,mode=600 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
none /acct cgroup rw,cpuacct 0 0
tmpfs /mnt/asec tmpfs rw,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,mode=755,gid=1000 0 0
none /dev/cpuctl cgroup rw,cpu 0 0
/dev/block/mtdblock0 /system yaffs2 ro 0 0
/dev/block/mtdblock1 /data yaffs2 rw,nosuid,nodev 0 0
/dev/block/mtdblock2 /cache yaffs2 rw,nosuid,nodev 0 0

Again, I am launching the AVD programmatically from an Ant script. 我再次以编程方式从Ant脚本启动AVD。 Is there something I can do programmatically to mount the sdcard? 我可以通过编程方式安装SD卡吗?

Found the problem! 发现问题了! When I created the AVD I never specified the size of the SD card. 当我创建AVD时,我从未指定过SD卡的大小。 I edited and set a size of 512MiB and now it's writeable! 我编辑并设置了512MiB的大小,现在它是可写的! Thanks all who replied! 谢谢所有回复的人! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM