我有这样的代码:
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);
}
但是当我打开 FileOoutputStream 时,我总是得到这个异常:
java.io.FileNotFoundException: /mnt/sdcard/Android/data/com.whatever/cache/m_images.jpeg (Is a directory)
你能说这个问题的原因在哪里吗?为什么文件不创建?