Is there a difference between / mnt / sdcard and / sdcard?

I am trying to save a bitmap in the Pictures directory. Here is the code

            File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

            File file = new File(path, "test1.PNG");
            try { 
                   path.mkdirs();
                   OutputStream out = new FileOutputStream(file);
                   mBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                   out.flush();
                   out.close();

            } catch (Exception e) {
                   e.printStackTrace();
                   Log.w("ExternalStorage", "Error writing " + file, e);
            }

But execution got stuck in OutputStream out = new FileOutputStream(file); I used a debugger, and the full path returns mnt/sdcard/Pictures/test1.PNG, is the mnt/culprit, why couldn’t I pass by OutputStream out = new FileOutputStream(file);? Because I can only see sdcard/in my file directory.

thank!

+5
source share
3 answers

You can access and access the sdcard directory using this one Environment.getExternalStorageDirectory(), like mnt / sdcard or sdcard / its device-dependent directory, which, like the OS was accessed, and use an external directory, no need to worry about another device, and the other directory was return by this method.

EDIT

androidmanifest.xml

WRITE_EXTERNAL_STORAGE
+1

/sdcard - /mnt/sdcard... /sdcard , /mnt/sdcard/..

+3

use

 String filePath = "/sdcard/yourfile.txt";

 FileOutputStream os = null;
 os = new FileOutputStream(filePath); 
 os.write(write it to file);
 os.close();
0
source

All Articles