Java流中flush()的目的是什么? [英] What is the purpose of flush() in Java streams?

查看:30
本文介绍了Java流中flush()的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 中,flush() 方法用于流中.但是我不明白使用这种方法的所有目的是什么?

In Java, flush() method is used in streams. But I don't understand what are all the purpose of using this method?

fin.flush();

告诉我一些建议.

推荐答案

来自 文档:

From the docs of the flush method:

刷新输出流并强制写出任何缓冲的输出字节.刷新的一般约定是调用它表明,如果先前写入的任何字节已被输出流的实现缓冲,则应立即将这些字节写入其预期目的地.

Flushes the output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

缓冲主要是为了提高I/O性能.可以从这篇文章中阅读更多相关信息:调整 Java I/O 性能.

The buffering is mainly done to improve the I/O performance. More on this can be read from this article: Tuning Java I/O Performance.

这篇关于Java流中flush()的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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