Writing to a Specific Folder on an SD Card in Android
When using the code snippet provided to download and write a file to the root directory of the SD card, you may want to specify a specific folder to write the file to. This can be achieved by modifiying the code to create a directory and then write the file to that directory.
File sdCard = Environment.getExternalStorageDirectory(); // Get the SD card root directory File dir = new File (sdCard.getAbsolutePath() + "/dir1/dir2"); // Create a directory with the desired path dir.mkdirs(); // Create the directory if it doesn't exist File file = new File(dir, "filename"); // Create a new file in the directory FileOutputStream f = new FileOutputStream(file); // Open the file for writing ...
With this modification, the file will be written to the specified folder instead of the root directory of the SD card.
The above is the detailed content of How to Write Files to a Specific Directory on an Android SD Card?. For more information, please follow other related articles on the PHP Chinese website!