在Java中,当我调用OutputStream.close()时是否总是需要先调用OutputStream.flush()? [英] In Java, when I call OutputStream.close() do I always need to call OutputStream.flush() before?

查看:3113
本文介绍了在Java中,当我调用OutputStream.close()时是否总是需要先调用OutputStream.flush()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在输出流中调用 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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆