How to check if newly created folder is present into SD Card in Android
16,424
Solution 1
below code will create a directory if it does not exist
File direct = new File(Environment.getExternalStorageDirectory() + "/New Folder");
if(!direct.exists())
{
if(direct.mkdir())
{
//directory is created;
}
}
Solution 2
You should request the following permission first in your Android manifest :
android.permission.WRITE_EXTERNAL_STORAGE
and execute above code by Rasel for it to work.
Related videos on Youtube
Comments
-
Jyosna almost 2 years
From my application, I want to store some images into my SD card. For that I need to create a one folder.
At the first time folder will create but after it checks whether that folder is present or not. How can I do it?
-
Jyosna almost 13 yearsThank you for ur answer. For addding image to that folder what i will do?
-
Jyosna almost 13 yearssave the image to sd card from canvas
-
Edward Falk over 11 yearsCouple of notes: you should be checking getExternalStorageDirectory() for a null return and/or calling getExternalStorageState() first. To save a file in your new directory, do "File ofile = new File(direct, ofilename);" and "FileWriter fw = new FileWriter(ofile);". Then write your image data to fw. Don't forget to close it when you're done. Wrapping it in a BufferedWriter might improve performance, depending on your application.
-
Bagusflyer almost 11 yearsWhat if I want to create multiple level folder. For example /New Folder1/New Folder2 ? Is there a simple call like ios sdk does? Thanks