user1951072 user1951072 - 4 months ago 31
Android Question

android mkdirs in SD card return false.help me, it spends me 3days

I want to create a folder in SD card ,and i already add the permission

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


in manifest file.below is my code,but mkdirs return false! Can you help me!

File exportDir = new File(
Environment.getExternalStorageDirectory().toString(), "happydiarybackup");
if (!exportDir.exists()) {
boolean a = exportDir.mkdirs();
Log.d("mkdir ",exportDir.getAbsolutePath() + " make "+ a);
}

Answer

Try this. It might help you.

String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/happydiarybackup/";
try
{
    File dir = new File(fullPath);
    if (!dir.exists()) {
      dir.mkdirs();
    }
}
 catch (Exception e) {
   Log.e("App", "Exception" + e.getMessage());
}
Comments