【发布时间】:2015-04-01 11:58:04
【问题描述】:
写入OutputStream 时,如果远程机器关闭或已断开连接,它将抛出IOException 异常。现在,我想在仅(且仅)管道损坏时调用特定方法。问题是IOException 没有code 或errno 属性来检查此错误。而我能够做到这一点的唯一方法是
try {
stream.write(message.getBytes("UTF8"));
stream.flush();
} catch (IOException e) {
if (e.getMessage().equals("sendto failed: EPIPE (Broken pipe)")) {
// perform a specific action
} else {
e.printStackTrace();
}
}
显然这不是实现这一目标的完美方式。有什么有效解决方案的建议吗?
【问题讨论】:
标签: java android ioexception broken-pipe