Can't create folder in extsd card

2019-02-20 19:09发布

问题:

I have an android tablet where external SD card called "/mnt/extsd" and its internal storage called "/mnt/sdcard".

When I am try to create a folder in "/mnt/sdcard" by the following code. Application successfully creates folder in root directory, while I try to create folder in "/mnt/extsd" it toast an exception "open failed: EACCESS (Permission denied)"

    // create a File object for the parent directory
    File root_directory = new File("/mnt/extsd/abc/");
    // have the object build the directory structure, if needed.
    root_directory.mkdirs();
    // create a File object for the output file
    File outputFile = new File(root_directory, "abc_checking");
    // now attach the OutputStream to the file object, instead of a String representation
    try {
        FileOutputStream fos = new FileOutputStream(outputFile);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        Utility.showDialogue(getActivity(), e.getMessage() + "");
    }

Manifest

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Any help from you guys will be very appreciable. Please HELP...:(

回答1:

If Environment.getExternalStorageDirectory() returns /mnt/sdcard/, then that is the external storage that you should be using in your application. While your device may have other mount points (e.g., /mnt/extsd/), those are not part of the Android SDK and will be more or less unique to your specific device. You will need to contact your device's manufacturer to ask them if there is a way you can use /mnt/extsd/ from a regular SDK application.

If you have root access, you might be able to work around this by changing permissions on /mnt/extsd/, but that is not really a programming topic and therefore is beyond the scope of StackOverflow.