I cannot create a folder in android External Storage Directory.
I have added permissing on manifest,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Here is my code:
String Path = Environment.getExternalStorageDirectory().getPath().toString()+ "/Shidhin/ShidhiImages"; System.out.println("Path : " +Path ); File FPath = new File(Path); if (!FPath.exists()) { if (!FPath.mkdir()) { System.out.println("***Problem creating Image folder " +Path ); } }
Android External Storage Example Code getExternalFilesDir(): It returns the path to files folder inside Android/data/data/application_package/ on the SD card. It is used to store any required files for your app (like images downloaded from web or cache files).
To read and write data to external storage, the app required WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE system permission. These permissions are added to the AndroidManifest. xml file. Add these permissions just after the package name.
Show activity on this post. File mydir = context. getDir("mydirectory", Context. MODE_PRIVATE); //Creating an internal dir; File fileWithinMyDir = new File(mydir, "myAwesomeFile"); //Getting a file within the dir.
Do it like this :
String folder_main = "NewFolder"; File f = new File(Environment.getExternalStorageDirectory(), folder_main); if (!f.exists()) { f.mkdirs(); }
If you wanna create another folder into that :
File f1 = new File(Environment.getExternalStorageDirectory() + "/" + folder_main, "product1"); if (!f1.exists()) { f1.mkdirs(); }
The difference between mkdir
and mkdirs
is that mkdir
does not create nonexistent parent directory, while mkdirs
does, so if Shidhin
does not exist, mkdir
will fail. Also, mkdir
and mkdirs
returns true only if the directory was created. If the directory already exists they return false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With