Everything is in the question. Here is my code :
private void createDirectory(File currentDirectory) {
File f = null;
try {
f = new File(current
You have to add this permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
By the way, not sure how you are getting the SDcard directory... but it must be this way:
File sdDir = Environment.getExternalStorageDirectory();
It's important, because some programmers use to think that the SDCard is always /sdcard, but it could change.
instead of boolean success = f.mkdir();
use
boolean success = f.mkdirs();
that solved my problem (i used the same reference code as you and had the same issue).
You're going to need to add
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to your manifest file to tell Android to ask the user for your application to be allowed to.
First, please use the File
constructor that takes a File
for your directory and a String
for your desired subdirectory.
Beyond that, most likely you are attempting to create a directory where you are not allowed, either because:
currentDirectory
does not exist, orcurrentDirectory
points to a place on the on-board flash storage where you are not allowed to write, orcurrentDirectory
points to a place on the external storage and you lack the WRITE_EXTERNAL_STORAGE
permission