Описание тега streamwriter
In.Net StreamWriter
(under System.IO
) 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 without a byte order mark (BOM), so its GetPreamble
method returns an empty byte array. The default UTF-8 encoding for this constructor throws an exception on invalid bytes. This behavior is different from the behavior provided by the encoding object in the Encoding.UTF8
property. To specify a BOM and determine whether an exception is thrown on invalid bytes, use a constructor that accepts an encoding object as a parameter, such as StreamWriter(String, Boolean, Encoding)
or StreamWriter.
By default, a StreamWriter
is not thread safe
See official documentation from Microsoft.