有时(现在我正在努力弄清楚模式),我的bitmap.compress
失败并出现以下错误:
java.io.IOException: write failed: EBADF (Bad file descriptor)
at libcore.io.IoBridge.write(IoBridge.java:498)
at java.io.FileOutputStream.write(FileOutputStream.java:186)
at android.graphics.Bitmap.nativeCompress(Native Method)
at android.graphics.Bitmap.compress(Bitmap.java:1027)
<...>
Caused by: android.system.ErrnoException: write failed: EBADF (Bad file descriptor)
at libcore.io.Posix.writeBytes(Native Method)
at libcore.io.Posix.write(Posix.java:271)
at libcore.io.BlockGuardOs.write(BlockGuardOs.java:313)
at libcore.io.IoBridge.write(IoBridge.java:493)
... 11 more
: ------- write threw an exception
代码看起来很标准:
FileDescriptor fileDescriptor = getMediaFileDescriptor(thumbUri);
OutputStream outputStream = null;
if (fileDescriptor != null) {
outputStream = new FileOutputStream(fileDescriptor);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream);
}
getMediaFileDescriptor()
这样做:
private FileDescriptor getMediaFileDescriptor(Uri uri) {
try {
ParcelFileDescriptor fileDescriptor = mContext.getContentResolver()
.openFileDescriptor(uri, "w");
return (fileDescriptor != null) ? fileDescriptor.getFileDescriptor() : null;
} catch (FileNotFoundException e) {
<...>
}
return null;
}
对此有什么好的解决方法,为什么会发生?还有什么是坏的&#39;文件描述符?