Writing to a Subfolder on an Android SD Card
In Android programming, you can easily write files to the root directory of the SD card using Environment.getExternalStorageDirectory(). However, you may want to specify a specific folder to store your files in.
To write to a subfolder on the SD card, follow these steps:
Obtain an instance of the SD card's root directory:
File sdCard = Environment.getExternalStorageDirectory();
Create the desired subfolder (if it doesn't exist):
File dir = new File(sdCard.getAbsolutePath() + "/dir1/dir2"); dir.mkdirs();
Create a file within the subfolder for writing:
File file = new File(dir, "filename");
Use a FileOutputStream to write your data to the file:
FileOutputStream f = new FileOutputStream(file); ...
By following these steps, you can write files to any subfolder on the SD card. This is especially useful for organizing and storing your app's data in a structured manner.
The above is the detailed content of How to Write Files to a Specific Subfolder on an Android SD Card?. For more information, please follow other related articles on the PHP Chinese website!