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

查看:407
本文介绍了在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();

告诉我一些建议。

推荐答案

来自 flush 方法的> docs:

From the docs of the flush method:


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

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天全站免登陆