StreamWriter.Flush Method
Clears all buffers for the current writer and causes any buffered data to be written to the underlying stream.
[Visual Basic] Overrides Public Sub Flush() [C#] public override void Flush(); [C++] public: void Flush(); [JScript] public override function Flush();
Exceptions
| Exception Type | Condition |
|---|---|
| ObjectDisposedException | The current writer is closed. |
| IOException | An I/O error has occurred. |
Remarks
This method overrides Flush.
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.
The following table lists examples of other typical or related I/O tasks.
| To do this... | See the example in this topic... |
|---|---|
| Create a text file. | Writing Text to a File |
| Write to a text file. | Writing Text to a File |
| Read from a text file. | Reading Text from a File |
| Append text to a file. | Opening and Appending to a Log File |
| Get the size of a file. | FileInfo.Length |
| Get the attributes of a file. | File.GetAttributes |
| Set the attributes of a file. | File.SetAttributes |
| Determine if a file exists. | File.Exists |
| Read from a binary file. | Reading and Writing to a Newly Created Data File |
| Write to a binary file. | Reading and Writing to a Newly Created Data File |
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
StreamWriter Class | StreamWriter Members | System.IO Namespace | Close | Working with I/O | Reading Text from a File | Writing Text to a File