Mono Class Library: System.IO Namespace

System.IO.StreamWriter Class

Implements a System.IO.Stream wrapper that writes characters to a stream in a particular encoding. [Edit]

See Also: StreamWriter Members

System.Object
     System.MarshalByRefObject
          System.IO.TextWriter
               System.IO.StreamWriter

[System.Runtime.InteropServices.ComVisible(true)]
public class StreamWriter : TextWriter

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

The System.IO.StreamWriter class is designed for character output in a particular System.Text.Encoding, whereas subclasses of System.IO.Stream are designed for byte input and output.

System.IO.StreamWriter defaults to using an instance of System.Text.UTF8Encoding unless specified otherwise. This instance of System.Text.UTF8Encoding is constructed such that the System.Text.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 System.IO.StreamWriter has 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.

Note: By default, System.IO.StreamWriter is not thread safe. For a thread-safe wrapper, see TextWriter.Synchronized(TextWriter) .

[Edit]

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0