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() ...