Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
DiscardBufferedData Method

StreamReader.DiscardBufferedData Method

Allows a StreamReader to discard its current data.

[Visual Basic]
Public Sub DiscardBufferedData()
[C#]
public void DiscardBufferedData();
[C++]
public: void DiscardBufferedData();
[JScript]
public function DiscardBufferedData();

Remarks

Use DiscardBufferedData to seek to a known location in the underlying stream and then begin reading from this new point, or to read the contents of a StreamReader more than once. Because this method can cause slower performance, use it sparingly and only when you need it for a specific scenario.

Because read methods do not update the current position of the underlying stream, some class instances return more characters than are actually in the stream. One way around this problem is to use DiscardBufferedData, which causes the StreamReader to discard its internal buffer contents.

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

File.AppendText

FileInfo.AppendText

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

StreamReader Class | StreamReader Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Show:
© 2015 Microsoft