flush in java.io.FileWriter

后端 未结 9 1196
清酒与你
清酒与你 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 08:05

    You don't need to do a flush because close() will do it for you.

    From the javadoc:

    "Close the stream, flushing it first. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect."

提交回复
热议问题