Mike
Mike

Reputation: 95

How to create a folder in Download directory (Android Studio)

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

Answers (2)

xdevs23
xdevs23

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

mdDroid
mdDroid

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

Related Questions