简体   繁体   中英

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM