Eugene
Eugene

Reputation: 60224

Can't find created folder

I create a new folder:

String homeDir = "MyApp";
String home = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + homeDir;
File folder = new File(home);
        if (!folder.exists()) {
            return folder.mkdir();
        }

But it is never created, why?

Upvotes: 0

Views: 236

Answers (2)

Shiv
Shiv

Reputation: 4567

use mkdirs() instead of mkdir() and also add in ur manifest file the following permission :

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

Upvotes: 0

Niklas Ekman
Niklas Ekman

Reputation: 960

I suppose the parent folders do not exist. To create the folder you must then call folder.mkdirs() (notice the s).

This is from the File documentation:

public boolean mkdirs ()
Creates the directory named by this file, creating missing parent directories if necessary. Use mkdir() if you don't want to create missing parents.

Upvotes: 1

Related Questions