天天看点

filewriter判断是否关闭,java中filewriter的flush和close函数之间的区别

filewriter判断是否关闭,java中filewriter的flush和close函数之间的区别

I need to know what is exact difference between flush and close function in Java?

And When the data is dumped into a file during writing of file?

Please provide one example

解决方案

flush() writes the content of the buffer to the destination and makes the buffer empty for further data to store but it does not closes the stream permanently. That means you can still write some more data to the stream.

But close() closes the stream permanently. If you want to write some data further, then you have to reopen the stream again and append the data with the existing ones.