Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a folder on sd with subfolders

I got a problem with the following code:

    File folder = new File(Environment.getExternalStorageDirectory() + "/myapp/folderone/foldertwo");
    boolean success = false;
    if (!folder.exists()) {
        success = folder.mkdir();
    }
    if (!success) {
    } else {
    }

but its simply not working I also added the permission:

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

Hope someone could help me with this.

like image 333
ollidiemaus Avatar asked Jun 07 '12 15:06

ollidiemaus


1 Answers

Try to use mkdirs() instead of mkdir() only, this worked for me.

Example:

File folder = new File(Environment.getExternalStorageDirectory() + "/myapp/folderone/foldertwo");
    boolean success = false;
    if (!folder.exists()) {
        success = folder.mkdirs();
    }
    if (!success) {
    } else {
    }
like image 198
Thkru Avatar answered Sep 21 '22 22:09

Thkru