Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can make a folder within the Downloads or Documents directory using the following code:

File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "FolderName");
if (!folder.exists()) {
   folder.mkdir();
}

This code creates a new file object with the specified folder name ("FolderName") within the Downloads directory. The mkdir() method then creates the folder if it does not already exist.

Similarly, for the Documents directory, replace Environment.DIRECTORY_DOWNLOADS with Environment.DIRECTORY_DOCUMENTS in the getExternalStoragePublicDirectory() method.

File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "FolderName");
if (!folder.exists()) {
   folder.mkdir();
}