Implements a
TextWriter for writing characters to a stream in a particular encoding.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class StreamWriter
Inherits TextWriter
Dim instance As StreamWriter
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class StreamWriter : TextWriter
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class StreamWriter : public TextWriter
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public class StreamWriter extends TextWriter
SerializableAttribute
ComVisibleAttribute(true)
public class StreamWriter extends TextWriter
StreamWriter is designed for character output in a particular Encoding, whereas classes derived from Stream are designed for byte input and output.
StreamWriter defaults to using an instance of UTF8Encoding unless specified otherwise. This instance of UTF8Encoding is constructed such that the Encoding.GetPreamble method returns the Unicode byte order mark written in UTF-8. The preamble of the encoding is added to a stream when you are not appending to an existing stream. This means any text file you create with StreamWriter will have three byte order marks at its beginning. UTF-8 handles all Unicode characters correctly and gives consistent results on localized versions of the operating system.
By default, a StreamWriter is not thread safe. See TextWriter.Synchronized for a thread-safe wrapper.
The following table lists examples of other typical or related I/O tasks.
System.Object
System.MarshalByRefObject
System.IO.TextWriter
System.IO.StreamWriter
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
.NET Framework
Supported in: 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 2.0, 1.0