Home >Java >javaTutorial >How to Specify a Folder on an Android SD Card for File Writing?
Writing Files to a Specified Folder on an SD Card in Android
In the provided Android code snippet, the file is written to the root directory of the SD card using Environment.getExternalStorageDirectory(). To specify a particular folder, you can use the following steps:
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/dir1/dir2");
dir.mkdirs();
File file = new File(dir, "filename");
FileOutputStream f = new FileOutputStream(file);
By following these steps, you can specify a specific folder on the SD card to write the downloaded file to. Remember to replace "/dir1/dir2" with the actual path to the desired directory.
The above is the detailed content of How to Specify a Folder on an Android SD Card for File Writing?. For more information, please follow other related articles on the PHP Chinese website!