java - Java 流中 flush() 的目的是什么?

标签 java flush stream

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

fin.flush();

告诉我一些建议。

最佳答案

来自docs 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 性能。更多信息可以阅读这篇文章:Tuning Java I/O Performance .

关于java - Java 流中 flush() 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2340106/

相关文章:

c++ - 在 C++ 中刷新流的后果和优缺点

c++ - 为什么将 std::endl 与 ostringstream 一起使用会影响输出速度?

php - fgets() 和 fread() - 有什么区别?

java - 如何使用java向mySQL表中插入数据

java - 快速重复搜索快速增长的数组中是否存在值的最佳方法?

java - 无法在 Mongodb 中找到与 java 中的确切日期匹配的文档

java - 忽略设置界限

mysql - 如何在不重启 MySQLd 的情况下降低 MySQL 内存使用率

c# - 为什么NetworkStream Read会这样?

c - 在 dup2 之后,stream 仍然包含旧内容?