Reputation: 95
I'd like to create a directory in a Download directory (the one which stores all the files I download from web) so I can see it in browser after I plug the mobile into my PC.
File myDirectory = new File(dir, "NewDirectory");
What should be the value of dir?
Upvotes: 2
Views: 15626
Reputation: 3994
File dir = new File(Environment.getExternalStorageDirectory() + "/Download/your folder/");
dir.mkdirs(); // creates needed dirs
Don't forget to ask for permissions on Marshmallow or newer and to add the write storage permission to Android Manifest, for example: https://stackoverflow.com/a/34722591/4479004
Upvotes: 10
Reputation: 3195
try following code
private void createDirectoryAndSaveFile() {
File direct = new File(Environment.getExternalStorageDirectory() + "/Download/DirName");
if (!direct.exists()) {
File wallpaperDirectory = new File("/sdcard/Download/DirName/");
wallpaperDirectory.mkdirs();
}
}
Upvotes: 0