我有这段代码:
private void save(Bitmap bitmap) {
try {
FileOutputStream fos = new FileOutputStream(path);
bitmap.compress(Bitmap.CompressFormat.JPEG, COMPRESSION_QUALITY, fos);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我需要在FileNotFoundException
catch块中关闭FileOutputStream
吗?
如果抛出该异常,则意味着文件无法打开,因此我认为不必要。但是,在IOException
catch块中这样做会更好。
如果我不这样做,会导致内存泄漏错误或类似问题吗?
谢谢。
FileOutputStream fos = null;
开始。 - greenapps