我实现了一个文件缓存来为长网格视图加载小图像。滚动一段时间后,我得到了很多libcore.io.ErrnoException: open failed: EMFILE (Too many open files)
我该如何避免这种情况?这是读取一个位图的代码:
File fullCacheDir = new File(Environment.getExternalStorageDirectory().toString(), cacheDir);
File file = new File(fullCacheDir.toString(), fileName);
if (!file.exists()) {
return null;
}
Bitmap bm = BitmapFactory.decodeFile(file.toString());
这是为了保存一个位图:
FileOutputStream outputStream = new FileOutputStream(fileUri);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.flush();
outputStream.close();