问题描述
如果我在输出流中调用 close()
,则输出是有保证的,或者需要调用 flush()
总是?
Close()总是刷新所以不需要调用。 b $ b
编辑:这个答案是基于常识和我遇到的所有输出流。谁将实现一个缓冲流的close()而不首先刷新缓冲区? close()之前调用flush是没有害处的。但是,如果flush()被过度调用,会有后果。它可能会破坏缓冲机制。
If I just call close()
in a output stream, the output is guaranteed, or need I call flush()
always?
Close() always flushes so no need to call.
EDIT: This answer is based on common sense and all the outputstream I encountered. Who is going to implement a close() for a buffered stream without flushing buffer first? There is no harm to call flush right before close(). However, there are consequences if flush() is called excessively. It may defeat underneath buffering mechanism.
这篇关于在Java中,当我调用OutputStream.close()时是否总是需要先调用OutputStream.flush()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!