Question

Which way is the best to save file on external storage...

a) new File(Enviroment.getExternalStorageDirectory(), "")

b) new File("/mnt/sdcard/","")

Was it helpful?

Solution 2

Always use

 Enviroment.getExternalStorageDirectory().getPath()

instead of hard coding as below...

/mnt/sdcard/

If you choose hard coding way then the system will throw you below message...

Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead

Another problem is that SDCard folder name isn't same for all devices...SDCard name different in Some devices.

In samsung devices, it is named external_sd and in this case, the hard coding way will be failed. That's why following way is the best...

File file = new File(Enviroment.getExternalStorageDirectory().getPath(), "");

OTHER TIPS

Enviroment.getExternalStorageDirectory() is the best way to save file into external storage. Take a look at this http://developer.android.com/reference/android/os/Environment.html

Always use

Enviroment.getExternalStorageDirectory() in place of mnt/sdcard/

Enviroment.getExternalStorageDirectory() is the best public API for directly accessing the SD card.

However, you should consider using the new ACTION_CREATE_DOCUMENT intent which allows the user to select a location for saving.

For example, if a device has multiple SD cards, the user can select between them, or they can choose any app participating in the Storage Access Framework.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top