我正在尝试正确处理IOException
,而不必求助于大量嵌套的 try/catch 语句。
通过在线阅读,我发现这可能是处理它的正确方法。但我不是100%确定。这是正确的吗?
try (InputStream in = blob.getBinaryStream()) {
while (in.read(bytesRead) != -1) {
byteStream.write(bytesRead);
}
}catch(IOException e){
logger.error("An IOException occurred while streaming a blob from the database", e);
}
最佳答案
InputStream
in
将被关闭,byteStream
则不会。
关于java - 如果发生IOException,这个InputStream会被正确关闭吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48828857/