Usage of flush in "C #" System.IO.Stream

Source: Internet
Author: User

Msdn:

For an example of creating a file and writing text to a file, see how to: Write Text to a file. For an example of reading text from a file, see how to: Read Text from a file. For an example of reading and writing a binary file, see how to: Read and write to a new data file.

Rewrite the Flush on the stream that implements the buffer. Use this method to move all information from the underlying buffer to its destination or to clear the buffer, or both. Depending on the state of the object, you may need to modify the current position within the stream (for example, if the underlying stream supports lookups). For additional information, see CanSeek.

If the implementation of Flush or close is not explicitly invoked, the refresh stream will not flush its underlying encoder. Setting AutoFlush to true means flushing data from the buffer to the stream without refreshing the encoder state. This allows the encoder to remain in its state (incomplete characters) so that it can correctly encode the next character at descriptor. This scenario affects UTF8 and UTF7, where some characters can only be encoded after the encoder receives one or more adjacent characters.

Summarize:

When the stream is used, its connection is connected to the source stream, and the other end is connected to the target device (such as files, buffers, Bluetooth devices, etc.), and some types of streams can set buffers between the links to the target device. The role of the Flush () function is to force the contents of the current buffer to be written to the target device, preparing for the next write.

Some stream streams store data, and when you call write (), you may not be able to immediately transmit the information to the target device, perhaps until the buffer is not large enough or stream.close () before the transfer operation, so good habit is, Timed use of flush () to control buffer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.