【发布时间】:2011-08-27 09:33:19
【问题描述】:
我经历了多个关于 SD 卡文件写入问题的主题,但找不到对我有帮助的答案。
- 我用过
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在我的节点清单中。
2. 以下代码创建一个文件但不写入文件。 Writer 也从不抛出异常。当我回到 SDCard 并看到创建的文件为 0 kb 时。 (这是由于 createnew 函数)
3. SDCard 显示使用这些权限创建的文件----rwxr-x(写不存在为其他人)
4. 模拟器或设备如 ASUS pad 或 Acer Iconia 设备上的行为相同。
应用程序从 Android 应用程序创建包含 SDCard 内容的文件的常规方式是什么?
if(isExternalStorageWritable()) {
File testFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),Filename);
try {
if (testFile.createNewFile()) {
Log.i(TAG + ": createSdcardFile","Empty file on external storage created");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
openFileOutput(Filename, MODE_APPEND)));
out.write(Content);
out.close();
Log.i(TAG + ": createSdcardFile","Content to new file created");
created = true;
}
} catch(IOException e) {
Log.e(TAG,"Unable to create/write to new file on external storage. Terminating testCDMReadPositive");
Log.e(TAG,e.getMessage());
}
}
4.使用模式 MODE_WORLD_WRITABLE 给出相同的结果,即 SDCard 上的 0kb 文件
5. 任何有在 externalstorage ( /mnt/sdcard ) 上写入文件经验的人都知道如何做到这一点。任何帮助或方向,高度赞赏。谢谢
【问题讨论】: