Is it safe to use Apache commons-io IOUtils.closeQuietly?

前端 未结 4 393
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 05:42

Is this code

    BufferedWriter bw = new BufferedWriter(new FileWriter(\"test.txt\"));
    try {
        bw.write(\"test\");
    } finally {
        IOUtils         


        
4条回答
  •  粉色の甜心
    2020-12-24 06:10

    It is safe so long as your application doesn't care whether the write succeeded without error. If your application needs to handle write errors it is not safe as buffered data flushed on close may be lost and the error swallowed.

提交回复
热议问题