Why would I care about IOExceptions when a file is closed?

前端 未结 3 1663
迷失自我
迷失自我 2021-02-13 15:06

I\'ve see this sort of thing in Java code quite often...

try
{
    fileStream.close();
}
catch (IOException ioe)
{
    /* Ignore. We do not care. */
}

3条回答
  •  孤街浪徒
    2021-02-13 15:48

    You would care if the close() method flushes written content from a buffer to the filesystem, and that fails. e.g. if the file you're writing to is on a remote filesystem that has become unavailable.

    Note that the above re. flushing applies to any output stream, not just files.

提交回复
热议问题