Can't Create File In Sd-card
I am trying to save a bitmap to a file and then saving it on sd-card. Here's my code: String path = Environment.getExternalStorageDirectory().toString(); File file = new File(path,
Solution 1:
That logcat is saying you don't have permission to write the file, Make sure you have declared
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in the android manifest.
You can add this:
File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()+ "/%YOUR_FOLDER%/");
if (!(dir.exists() && dir.isDirectory())) {
dir.mkdirs();
}
above your current code if you want to try a different folder location for the file and see if that helps. The code will create the directory /sdcard/Downloads/YOUR_FOLDER/ in which you can create the file. See here for storage location options.
You can then do
Filefile=newFile(dir, "Jhs"+".jpg");
file.createNewFile(); //CREATE THE FILE FIRST!
OutputStream fOut;
try {
fOut = newFileOutputStream(file);
....
}
etc as in your post.
Solution 2:
Given the exception you are getting, you need to your AndroidManifest.xml
file the WRITE_EXTERNAL_STORAGE
permission
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Solution 3:
java.io.FileNotFoundException: /mnt/sdcard/Jhs.jpg (Permission denied)
Add this permission in Manifest
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Solution 4:
java.io.FileNotFoundException: /mnt/sdcard/Jhs.jpg (Permission denied)
It looks like you don't have WRITE_EXTERNAL_STORAGE perimission.
Add this to your AndroidMAnifest.xml:
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
Post a Comment for "Can't Create File In Sd-card"