StreamWriter Constructor (Stream)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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 Sub New ( _
	stream As Stream _


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


stream is not writable.


stream is Nothing.

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.

Version Notes

Windows Phone

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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2015 Microsoft