I have the code as this:
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
//create name based on time? just a simple link to photo
//save to cache file
File file = getExternalCacheDir();
if (file != null) {
try {
String root = file.getAbsolutePath();
File imageFile = new File(file, "m_images.jpeg");
boolean tr = imageFile.mkdirs();
FileOutputStream stream = new FileOutputStream(imageFile);
boolean complete = image.compress(Bitmap.CompressFormat.PNG, 90, stream);
if (!complete) {
Log.d("tag", "image doesn't saved");
}
Log.d("tag", "image saved");
} catch (IOException e) {
Log.d("tag", "Can't save image", e);
}
But I always get this exception when I open FileOoutputStream:
java.io.FileNotFoundException: /mnt/sdcard/Android/data/com.whatever/cache/m_images.jpeg (Is a directory)
Could you say where is the cause of this issue? Why file doesn’t create?
The exception
/mnt/sdcard/Android/data/com.whatever/cache/m_images.jpeg (Is a directory)
means it’s a directory. It would be execute well when remove the lineboolean tr = imageFile.mkdirs();