0

我的问题是我需要使用外部插槽 sdcard 中的文件,请不要建议我使用Environment.getExternalStorageDirectory()- 它是用于内部存储的,我想在外部存储中创建文件

4

2 回答 2

0

关于什么

File myFile = new File("/mnt/sdcard2/myFile");

编辑: 忘了提到你必须创建文件:

boolean fileCreated = myFile.createNewFile();
//at this point fileCreated must be true and the file must exists on your sdcard2

编辑 :

从 File.createNewFile() javadoc:

/**
 * ...
 * @return true if the file has been created, false if it
 *         already exists.
 * @throws IOException if it's not possible to create the file.
 */

所以要么创建文件,要么它已经存在,要么你得到一个 IOException... 或者你的代码没有调用 createNewFile() ...

于 2012-12-18T14:59:27.473 回答
0

我不认为这是可能的。当我在自己的应用程序上工作时,如果有内部可写内存,我也会遇到同样的问题。搜索了几天试图找出如何获得实际的外部 SD 卡但没有运气。

我认为这是因为android使用存储的方式,内部sd卡称为SDCARD,外部sd卡链接到SDCARD0(或者类似的东西我不记得了)。当您运行 getExternalStorage 时,它​​只会查找 SDCARD 并转到内部存储。

于 2012-12-18T16:39:18.830 回答