flush in java.io.FileWriter

后端 未结 9 1197
清酒与你
清酒与你 2020-11-30 07:33

I have a question in my mind that, while writing into the file, before closing is done, should we include flush()??. If so what it will do exactly? dont streams auto flush??

9条回答
  •  我在风中等你
    2020-11-30 07:49

    I would highly recommend to call flush before close. Basically it writes remaining bufferized data into file.

    If you call flush explicitly you may be sure that any IOException coming out of close is really catastrophic and related to releasing system resources.

    When you flush yourself, you can handle its IOException in the same way as you handle your data write exceptions.

提交回复
热议问题