问题
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?
回答1:
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
回答2:
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();
}
}
来源:https://stackoverflow.com/questions/36695734/how-to-create-a-folder-in-download-directory-android-studio