简体   繁体   中英

How to store only on external storage storage/sdcard0/?

I want to store data on external storage and Environment.getExternalStorageDirectory() returns /storage/emulated/0/ path and and when i store data on that directory it store data on storage/sdcard0/... and on /storage/emulated/0/

I need to store a great numbers of images on external storage How could i implement that?How could i get path on external storage?

How could I get path on external storage?

/storage/emulated/0/ and storage/sdcard0/ is basically the same, this is just an alias. On devices like the Nexus 5 and any other device that doesn't have a physical SD card, "external storage" means the device built-in storage which emulates an SD card. Environment.getExternalStorageDirectory() will point to this location so you are good to go using this method.

From the docs :

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

First of all find of path of external storage

String path = Environment.getExternalStorageDirectory().toString() + directoryName;

then you can write whatever content you want to the file as follows:

File file = new File(path, fileName);
        BufferedWriter br;
        try {
            br = new BufferedWriter(new FileWriter(file));
            br.write(content);
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

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