I'm trying to save an image to my sdcard but running into the following error:
java.io.IOException: Parent directory of file does not exist: /sdcard/skdyImages/a46e2e08-9154-4fe7-96e8-2af0a7a92867.jpg
I do have the p开发者_JAVA技巧ermissions in my manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Here is my code:
String newName = UUID.randomUUID().toString();
Bitmap bmp = ImageLoader.getInstance().getBitmap(e.getUrl());
File file = new File("/sdcard/skdyImages", newName + ".jpg");
file.getParentFile().mkdirs();
file.createNewFile();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
bmp.compress(CompressFormat.JPEG, 90, out);
out.flush();
out.close();
Any ideas?
Try something like this...
// Automatically creates folder on sdcard called /Android/data/<package>/files
// if it doesn't exist
File ImageDir = new File(getExternalFilesDir(null).getAbsolutePath());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(ImageDir + "/" + newName + ".jpg"));
精彩评论