我正在尝试将图像保存到我的SD卡,但遇到以下错误:
java.io.IOException: Parent directory of file does not exist: /sdcard/skdyImages/a46e2e08-9154-4fe7-96e8-2af0a7a92867.jpg
我的清单中有权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
这是我的代码:
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();
有什么想法吗?
答案 0 :(得分:0)
尝试这样的事情......
// 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"));