为什么我们在c#中调用binarywriter的flush方法 [英] why do we call the flush method of binarywriter in c#

查看:726
本文介绍了为什么我们在c#中调用binarywriter的flush方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们在关闭它之前调用二进制文件的flush方法。flush方法实际上做了什么,是否需要在关闭它之前调用binarywriter的flush方法。

why do we call the flush method of the binarywriter before closing it.what does the flush method actually do and is it necessary to call the flush method of binarywriter before closing it.

推荐答案

它清除当前writer 的所有缓冲区,并将所有缓冲的数据写入底层设备



注意:所有派生类都应该重写Flush以确保将所有缓冲的数据发送到流。

刷新流不会刷新其底层编码器,除非您明确调用Flush或关。将AutoFlush设置为true意味着数据将从缓冲区刷新到流,但不会刷新编码器状态。这允许编码器保持其状态(部分字符),以便它可以正确编码下一个字符块。此场景影响UTF8和UTF7,其中某些字符只能在编码器接收到相邻字符后进行编码。



干杯,

江户
It clears all buffers for the current writer and causes any buffered data to be written to the underlying device.

NOTE: All derived classes should override Flush to ensure that all buffered data is sent to the stream.
Flushing the stream will not flush its underlying encoder unless you explicitly call Flush or Close. Setting AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

Cheers,
Edo


当你想要将内容写入流而不关闭它时,你调用Flush - 这样就可以被另一个进程读取(假设你没有对它进行独占锁定)流的另一端的对象) - 通常不需要为大多数流调用它(除了一些加密流,其中刷新很重要)。

在流上调用Close将自动无论如何都要冲洗流。
You call Flush when you want to write the content to the stream without closing it - so that is can be read by another process (assuming you don''t have an exclusive lock on the object at the other end of the stream) - it is not normally necessary to call it for most streams (with the exception of some encrypted streams where flushing is important).
Calling Close on a stream will automatically Flush the stream anyway.


这篇关于为什么我们在c#中调用binarywriter的flush方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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