This documentation is archived and is not being maintained.

StreamWriter.Null Field

Provides a StreamWriter with no backing store that can be written to, but not read from.

[Visual Basic]
Public Shared ReadOnly Null As StreamWriter
[C#]
public static readonly StreamWriter Null;
[C++]
public: static StreamWriter* Null;
[JScript]
public static var Null : StreamWriter;

Remarks

Use Null to redirect output to a StreamWriter that will not consume any operating system resources.

When the StreamWriter.Write methods are invoked on Null, the call simply returns, and no data is actually written to any backing store.

For an example of using this field, see the Example section below. 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

Example

[Visual Basic, C#, C++] The following example demonstrates a use of the Null field.

[Visual Basic] 
If Sw.Equals(StreamWriter.Null) Then
    Sw.WriteLine("The store can be written to, but not read from.")
End If

[C#] 
if(sw.Equals(StreamWriter.Null)) 
{
    sw.WriteLine("The store can be written to, but not read from.");
}

[C++] 
if(sw->Equals(StreamWriter::Null)) 
{
   sw->WriteLine(S"The store can be written to, but not read from.");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

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

See Also

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

Show: