无法写入即使在MEDIA_MOUNTED状态设置权限和外部存储到SD卡 [英] Can't write to sdcard even with permissions set and external storage in MEDIA_MOUNTED state

查看:1783
本文介绍了无法写入即使在MEDIA_MOUNTED状态设置权限和外部存储到SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图写文件到SD卡,我得到 java.io.FileNotFoundException:/文件名(只读文件系统)例外。可悲的是没有张贴在这里的众多解决方案帮助了我。我已经设置了权限和外部存储设备处于MEDIA_MOUNTED状态。
这是有问题的code:

While trying to write file to sdcard I get java.io.FileNotFoundException: /filename (Read-only file system) exception. Sadly none of the many solutions posted here helped me. I have set the permissions and external storage is in MEDIA_MOUNTED state. This is the problematic code:

Log.i("STORAGE", Environment.getExternalStorageState());
OutputStream fos = new FileOutputStream(Helpers.StripExtension(filePath) + ".blk");
fos.write(digest.getBytes());
fos.close();    

文件路径来自文件的股票。我试图做的是从选定的文件中读取,然后保存使用相同的名称,不同的扩展,有些东西在它的另一个文件。

filePath comes from file ticker. What I'm trying to do is reading from chosen file, and then saving another file with the same name, different extension and some stuff in it.

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mypackagename"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="15" />

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:theme="@android:style/Theme.Black" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

logcat的:

 10-25 18:24:34.330: I/FILEPATH(1989): /mnt/sdcard/Untitled.txt
 10-25 18:24:34.360: I/STORAGE(1989): mounted
 10-25 18:24:34.360: W/System.err(1989): java.io.FileNotFoundException: /mnt/sdcard/Untitled.blk (Read-only file system)
 10-25 18:24:34.360: W/System.err(1989):    at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
 10-25 18:24:34.360: W/System.err(1989):    at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
 10-25 18:24:34.360: W/System.err(1989):    at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
 10-25 18:24:34.360: W/System.err(1989):    at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
 10-25 18:24:34.360: W/System.err(1989):    at java.io.FileOutputStream.<init>(FileOutputStream.java:144)

我是一个真正的设备上运行这个,不是AVD。我试图重新启动我的设备和重建项目。像OfficeSuite应用程序可以写入到这个位置没有问题。

I'm running this on a real device, not avd. I've tried rebooting my device and rebuilding project. Applications like OfficeSuite can write to this location with no problem.

设备:中兴刀片采用Android 2.3.7(7的CyanogenMod)

Device: ZTE Blade with Android 2.3.7 (CyanogenMod 7)

推荐答案

大,我有完全相同的问题,前一段时间。路径分隔符(或任何它被称为)丢失。

Great, I've had the exact same problem some time ago. Path delimiter (or whatever it's called) is missing.

File file = new File(Environment.getExternalStorageDirectory() + "test_file.blk");

没有工作,但

File file = new File(Environment.getExternalStorageDirectory() + "/test_file.blk");

表现不错

还有:

FileWriter f = new FileWriter(Environment.getExternalStorageDirectory().getPath()+ "/foobar");
f.append("stuff");
f.close();

做工精细等结果
我觉得异常说这是只读的,因为根文件系统是只读确实如此。

Works fine etc.
I think exceptions said it's readonly, because root filesystem is readonly indeed.

请注意:结果
java.io.FileNotFoundException:/ foobar的(只读文件系统)意味着我们正在编写系统的root结果
java.io.FileNotFoundException:到/ mnt / SD卡/ foobar的(只读文件系统)表示SD卡根(我没有得到这个例外,它只是一个例子)

NOTE:
java.io.FileNotFoundException: /foobar (Read-only file system) means we are writing to the system root
java.io.FileNotFoundException: /mnt/sdcard/foobar (Read-only file system) means sdcard root (I didn't get this exception it's just an example)

TL;博士错误的道路。

这篇关于无法写入即使在MEDIA_MOUNTED状态设置权限和外部存储到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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