Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

StreamWriter Constructor (Stream)

Initializes a new instance of the StreamWriter class for the specified stream, using UTF-8 encoding and the default buffer size.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

public StreamWriter(
	Stream stream
)

Parameters

stream
Type: System.IO.Stream
The stream to write to.

ExceptionCondition
ArgumentException

stream is not writable.

ArgumentNullException

stream is null.

This constructor creates a StreamWriter with UTF-8 encoding without a byte order mark (BOM), so its GetPreamble method returns an empty byte array. The BaseStream property is initialized using the stream parameter.

The StreamWriter object calls Dispose on the provided Stream object when StreamWriter.Dispose is called.

Caution noteCaution:

When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable and could cause an exception to be thrown.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 If you pass an invalid input path to a StreamWriter constructor, the constructor throws InvalidArgumentException instead of DirectoryNotFoundException.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft