2

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?

Mike
  • 95
  • 1
  • 2
  • 10

2 Answers2

8
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

xdevs23
  • 3,824
  • 3
  • 20
  • 33
0

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();
 }
}
mdDroid
  • 3,135
  • 2
  • 22
  • 34
  • 1
    Hi, never use "/sdcard/" while creating files or directories..always use Environment.getExternalStorageDirectory(). it gives the primary shared/external storage directory. – krishnamahadik Apr 18 '16 at 14:01