close是否会抛出IOException? [英] Does close ever throw an IOException?

查看:163
本文介绍了close是否会抛出IOException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里提供了一些答案并阅读了一些评论之后,实际上似乎IOException永远不会在文件I / O关闭时抛出。

After providing some answers here, and reading some comments, it would seem that, in practice IOException is never thrown on close for file I/O.

是否有在Stream / Reader / Writer上调用close实际抛出IOException的任何情况?

Are there any cases in which calling close on a Stream/Reader/Writer actually throws an IOException?

如果实际抛出异常,应如何处理?

If an exception is actually thrown, how should it be dealt with?

推荐答案

对于文件,你可能看不到关闭()经常抛出的IOException,但你肯定会看到非文件I / O喜欢关闭网络套接字。

For files, you may not see IOException thrown often on close(), but you'll definitely see it for non-File I/O like closing sockets to the network.

这是一个Java错误的示例,其中关闭UDP套接字最终导致抛出IOException。

Here's an example of a Java bug where closing a UDP socket eventually caused an IOException to be thrown.

这篇关于close是否会抛出IOException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆