Reputation: 1051
I am trying to create a directory and code runs without raising an exception, but directory is not created (checked with Android File Transfer app on Mac). There's no entry in the logs. What is going wrong here? Permissions are in place
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
Here's the code:
File path = getFilesDir();
File filenew = null;
try {
filenew= new File(path+"/equation");
filenew.mkdirs();
} catch (Exception e) {
e.printStackTrace();
}
Upvotes: 0
Views: 3275
Reputation: 606
Try it this way:
String externalDirectory= Environment.getExternalStorageDirectory().toString();
File folder= new File(externalDirectory + "/NewFolder");
folder.mkdir();
Upvotes: 2
Reputation: 3703
Try this
File root = new File(Environment.getExternalStorageDirectory(), "/MYFOLDER");
if(!root.exists()){
root.mkdirs();
}
Upvotes: 1