Creating a folder on sd with subfolders

Hi guys, I have a problem, I got 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 just not working, I also added permission:

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

Hope someone can help me.

+6
source share
2 answers

Try using mkdirs() instead of mkdir() , 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 { } 
+19
source

Have you tried calling mkdirs() instead of mkdir() ?

mkdir will only create one specified folder. In your case, "foldertwo".

mkdirs will create the specified folder (foldertwo) along with all other necessary folders in the path (myapp and folderone)

+3
source

Source: https://habr.com/ru/post/917538/


All Articles