当前位置:网站首页>Misunderstanding of flush () method of OutputStream class
Misunderstanding of flush () method of OutputStream class
2022-04-23 08:25:00 【beinlife】
Recently used java Of FileOutputStream Writing documents , Call to flush() Method .
So I looked at it FileInputStream Source code of class , Find out flush() In fact, it inherits from its parent class OutputStream Of .
and OutputStream Class flush() But I didn't do anything , See light suddenly , It's “ Look at the truth of the source code ”.
Actually flush() yes Flushable Interface method , The comment on this method in the official document is “Flushes this output stream and forces any buffered output bytes to be written out.”.
OutputStream Method implemented Flushable Interface , And did nothing , It's really confusing , So there was my misunderstanding .
So when flush() It works ?
The answer is : When OutputStream yes BufferedOutputStream when .
When writing files, you need flush() The effect of , need
FileOutputStream fos = new FileOutputStream("c:\a.txt");
BufferedOutputStream bos = new BufferedOutputStream(fos);
in other words , Need to put FileOutputStream As BufferedOutputStream The arguments of the constructor are passed in , Then on BufferedOutputStream Write operation , To take advantage of the buffer and flush().
see BufferedOutputStream Source code , Find the so-called buffer It's really just a byte[].
BufferedOutputStream Every time write It's actually writing content into byte[], When buffer When the capacity reaches the upper limit , Will trigger a real disk write .
Another way to trigger a disk write is to call flush() 了 .
版权声明
本文为[beinlife]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230734169269.html
边栏推荐
- clang 如何产生汇编文件
- 数据可视化:使用Excel制作雷达图
- WordPress love navigation theme 1.1.3 simple atmosphere website navigation source code website navigation source code
- MySQL数据库中delete、truncate、drop原理详解
- Qtablewidget header customization and beautification developed by pyqt5 (with source code download)
- LeetCode简单题之计算字符串的数字和
- Online yaml to XML tool
- Qt编译QtXlsx库
- jsp页面编码
- Flink SQL实现流批一体
猜你喜欢

The annotation is self-defined by implementing the parameter parser handlermethodargumentresolver interface

AQS & ReentrantLock 实现原理

RPC过程

vmware 搭建ES8的常见错误

Community group purchase applet source code + interface DIY + nearby leader + supplier + group collage + recipe + second kill + pre-sale + distribution + live broadcast

Overview of bus structure

Failed to convert a NumPy array to a Tensor(Unsupported Object type int)

怎么读书读论文

扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...

作文以记之 ~ 二叉树的后序遍历
随机推荐
如何保护开源项目免遭供应链攻击-安全设计(1)
【深度好文】Flink SQL流批⼀体化技术详解(一)
Rearranging log files for leetcode simple question
Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction
Compiling principle questions - with answers
One click cleanup of pycharm and jupyter cache files under the project
QT reads all files under the path or files of the specified type (including recursion, judging whether it is empty and creating the path)
DOM学习笔记---遍历页面所有元素节点
扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...
QT compilation qtxlsx Library
Interesting JS code
信息收集相关知识点及题解
Qt读写XML文件
jsp页面编码
2022.4.11-4.17 AI industry weekly (issue 93): the dilemma of AI industry
C language learning record -- use and analysis of string function (2)
Situational leaders - Chapter 7, solving performance problems
My heart's broken! A woman's circle of friends envied others for paying wages on time and was fired. Even her colleagues who liked her were fired together
2022.4.11-4.17 AI行业周刊(第93期):AI行业的困局
dried food! Point based: differentiable Poisson solver