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.
Are there any cases
It's specifically FileInputStream.close
which does not throw, even if your hard drive is on fire. Presumably it is the same for socket input. For output streams you may also be flushing. Until relatively recently [see timestamps] BufferedOutputStream
used to fail to close the underlying stream if flush
threw.
(@MaartenBodewes would like me to point out that FileInputStream.close
not throwing is not specified by the API docs. At the time of the post it was customary to elide the clause mentioning that this related to the Sun JDK (now known as Oracle JDK and OpenJDK). It appears that an obscure former reimplementation called Apache Harmony which Android used to use may have had different behaviour. Potentially other implementations, or versions of OpenJDK, may also throw.)