How to create new files in my external slot SDCARD ( its not in internal storage) - “/mnt/sdcard2/”

狂风中的少年 提交于 2019-12-12 03:31:32

问题


my question is I need to use files from my external slot sdcard, please dont suggest me to use Environment.getExternalStorageDirectory() - it is for internal storage I wanted to created files in external storage


回答1:


I don't think its possible. When I was working on my own app I encountered the same problem if there is internal writable memory. Searched for days trying to find out how how to get the actual external SD card but no luck.

I thinks its because the way android uses storage, the internal sd card is called SDCARD and the external one is linked to SDCARD0 (or something similar can't remember at the top of my head). When you run getExternalStorage it just looks for SDCARD and goes to the internal storage.




回答2:


What about

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

Edit : forgot to mention that you have to create the file:

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

Edit :

From 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.
 */

So either, the file is created, either it already exists, either you got an IOException... or your code didn't call createNewFile() ...



来源:https://stackoverflow.com/questions/13935584/how-to-create-new-files-in-my-external-slot-sdcard-its-not-in-internal-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!