[quote=引用 2 楼 oracleperl 的回复:][quote=引用 1 楼 sunyiz 的回复:] 当close时,如果你还在进行IO操作 会抛出这样一个异常 throw new IOException("Stream closed"); 所以,你可以捕捉异常信息的关键字, 检查是否有 closed 关键字 来判断对应的流是否已关闭 try { // IO操作 } catch (Exception e) { String err = e.getMessage(); if (err != null && err.indexOf("closed") > 0) { // 证明对应的流已关闭 } }
throw new IOException("Stream closed");
try { // IO操作 } catch (Exception e) { String err = e.getMessage(); if (err != null && err.indexOf("closed") > 0) { // 证明对应的流已关闭 } }
重复close会报错
如下,我如何在try catch里判断br和bw已经close()了?
[quote=引用 1 楼 sunyiz 的回复:] 当close时,如果你还在进行IO操作 会抛出这样一个异常 throw new IOException("Stream closed"); 所以,你可以捕捉异常信息的关键字, 检查是否有 closed 关键字 来判断对应的流是否已关闭 try { // IO操作 } catch (Exception e) { String err = e.getMessage(); if (err != null && err.indexOf("closed") > 0) { // 证明对应的流已关闭 } }
当close时,如果你还在进行IO操作 会抛出这样一个异常 throw new IOException("Stream closed"); 所以,你可以捕捉异常信息的关键字, 检查是否有 closed 关键字 来判断对应的流是否已关闭 try { // IO操作 } catch (Exception e) { String err = e.getMessage(); if (err != null && err.indexOf("closed") > 0) { // 证明对应的流已关闭 } }
62,612
社区成员
307,332
社区内容
加载中
试试用AI创作助手写篇文章吧