Morton
Morton

Reputation: 5782

Create folder failed when root is

Thanks for others help , i can create folder succeed now.

But i get a strange issue if android emulator doesn't has sdcard, i can't create the folder.

I can't figure it out..

Here is my code:

try {
            if (Environment.getExternalStorageState()
                    .equals(Environment.MEDIA_MOUNTED)) {
                System.out.println("can be read and write");
                File sdFile = android.os.Environment.getExternalStorageDirectory();
                //String path = sdFile.getPath() + File.separator + "DestPdf";
                String path = sdFile.getPath() + "/DestPdf";
                File dirFile = new File(path);

                if (!dirFile.exists()) {// if folder doesn't exist
                    System.out.println("create file");
                    dirFile.mkdirs();// create file
                    System.out.println(dirFile.toString());
                }
            }
        } catch (Exception ex) {
            ex.toString();
        }

If my android emulator has sdcard root, i can create the folder DestPdf: enter image description here If there is no sdcard , i print the root is /storage/emulated/0/DestPdf, i create the folder failed, the folder emulated has nothing... enter image description here

Any help would be appreciated . Thanks in advance.

Upvotes: 0

Views: 114

Answers (1)

Ankit Patidar
Ankit Patidar

Reputation: 2781

you can use your app Internal Package folder for saving data,

 context.getFilesDir().getPath()

context is here Activity instance.Ok?

Do with it..

Upvotes: 1

Related Questions