Monday, 29 November 2021

Create a folder in android external storage directory

Create a folder in android External Storage Directory.



Add  Permission on manifest,

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


Here is the Code,


String folder_main = "NewFolder"; 

File f = new File(Environment.getExternalStorageDirectory(), folder_main); 

if (!f.exists()) 

    f.mkdirs();


 

If you wanna create a parent folder into that you can use this code: 


File f1 = new File(Environment.getExternalStorageDirectory() + "/" + folder_main, "product1"); 

if (!f1.exists()) 

       f1.mkdirs(); 

No comments:

Post a Comment