0

This is my code

String DATA_PATH="/mnt/sdcard/";
        String[] paths = new String[] { DATA_PATH, DATA_PATH + "tessdata/" };
        for (String path : paths) {
            File dir = new File(path);
            if (!dir.exists()) {
                if (!dir.mkdirs()) {
                    Log.v("", "ERROR: Creation of directory " + path + " on sdcard failed");        
                } else {

                    Log.v("", "Created directory " + path + " on sdcard");
                }
            }

        }

I've tried using Environment.getExternalDirectory() but it still return false. The most confusing thing is it always said "ERROR: Creation of directory mounted on sdcard failed" on the logcat. How can the path changed into mounted? Can someone please give me a solution?

2 Answers2

1

if the mobile is connected to the system then we are not able to create folders so remove it and run the application

ravi
  • 319
  • 3
  • 15
0

Why are you using mkdirs in the first place ? You should just do:

File file = new File(Environment.getExternalStorageDirectory(), "tessdata");
if (!file.exists()) file.mkdir();

Also, make sure you have the WRITE_EXTERNAL_STORAGE permission in the manifest.

SirGregg
  • 100
  • 9