无法将文件保存到SD卡 [英] Can't save a file to SD card

查看:126
本文介绍了无法将文件保存到SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

Code:

String FILENAME = "settings";
String string = "hello world!";
File sdDir = new File(Environment.getExternalStorageDirectory().getPath());
File testDir = new File(sdDir.getAbsolutePath() + "/mobile_recont");
testDir.mkdir();

FILENAME = testDir + "/"+ FILENAME;
try {
    FileOutputStream fos = new FileOutputStream(FILENAME);
    fos.write(string.getBytes());
    fos.flush();
    fos.close();
    } catch (IOException e) {
Log.e("Controller", e.getMessage() + e.getLocalizedMessage() + e.getCause());
                    }





我也在清单中写道:



I also wrote in manifest:

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



但得到例外:


But get exception:

java.io.FileNotFoundException: /mnt/sdcard/mobile_recont/settings: open failed: EACCES (Permission denied)






and

Environment.getExternalStorageState() = "removed" 



为什么? - SD卡在模拟器中正确设置。

请帮助。


Why? - SD card is correctly setted in emulator.
Please help.

推荐答案

尝试在保存文件之前创建文件夹: http://stackoverflow.com/questions/4776426/how-to-create-a-directory -in-android [ ^ ]
Try creating the folders before saving files in them : http://stackoverflow.com/questions/4776426/how-to-create-a-directory-in-android[^]


SD卡侧面有一个写锁定滑块,距触点90度。



确保您的SD卡已启用写入。
SD cards have a "write lock" slider on the side, 90 degrees from the contacts.

Make sure that your SD card is write enabled.


这篇关于无法将文件保存到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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