android - How to create directory automatically on SD card -


I am trying to save my file to the following location
FileOutputStream fos = new FileOutputStream (" / Sdcard / wallpaper / "+ fileName"); but I'm getting exception java.io.FileNotFoundException , however, when I change the path to "/ sdcard /" < / Code> This works.

Now I am assuming that I am not able to create an auto directory like this.

Does anyone suggest how Directory and subdirectory Using code?

If you create an object that is the top-level directory, Make a file object for the parent directory: file wallpaper directory = new file ("/ sdcard / wallpaper /"); // Creates the object directory structure, if necessary, wallpaperDirectory.mkdirs (); // Create a file object for the output file file filefile = new file (wallpaperDirectory, filename); // Now attach the outputstream to the file object, instead of string presentation FileOutputStream fos = new FileOutputStream (outputFile); Note: Note: It may be wise to use it to get the "SD card" directory, because this can change the phone, with which the SD card (such as the built-in flash, Ella iPhone). Either way you should keep in mind that you have to check to make sure that it is actually there because SD card can be removed.

Update: Because API level 4 (1.6) 'permission must also be requested to do something similar (in the manifest):

 < Code> Android usage-permission: name = "android.permission.WRITE_EXTERNAL_STORAGE" />  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -