Search Results for

    Show / Hide Table of Contents

    Class StreamWriter

    Implements a TextWriter for writing characters to a stream in a particular encoding.

    Inheritance
    object
    MarshalByRefObject
    TextWriter
    StreamWriter
    Implements
    IDisposable
    Inherited Members
    TextWriter.CoreNewLine
    TextWriter.Dispose()
    TextWriter.Write(char[])
    TextWriter.Write(char[], int, int)
    TextWriter.Write(bool)
    TextWriter.Write(int)
    TextWriter.Write(uint)
    TextWriter.Write(long)
    TextWriter.Write(ulong)
    TextWriter.Write(float)
    TextWriter.Write(double)
    TextWriter.Write(string)
    TextWriter.Write(object)
    TextWriter.WriteLine(char)
    TextWriter.WriteLine(char[])
    TextWriter.WriteLine(char[], int, int)
    TextWriter.WriteLine(bool)
    TextWriter.WriteLine(int)
    TextWriter.WriteLine(uint)
    TextWriter.WriteLine(long)
    TextWriter.WriteLine(ulong)
    TextWriter.WriteLine(float)
    TextWriter.WriteLine(double)
    TextWriter.WriteLine(object)
    TextWriter.NewLine
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: System.IO
    Assembly: System.IO.Streams.dll
    Syntax
    public class StreamWriter : TextWriter, IDisposable

    Constructors

    StreamWriter(Stream)

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

    Declaration
    public StreamWriter(Stream stream)
    Parameters
    Type Name Description
    Stream stream

    The stream to write to.

    Exceptions
    Type Condition
    ArgumentNullException

    stream is null.

    ArgumentException

    stream is not writable.

    Properties

    BaseStream

    Gets the underlying stream that interfaces with a backing store.

    Declaration
    public virtual Stream BaseStream { get; }
    Property Value
    Type Description
    Stream

    The stream this StreamWriter is writing to.

    Encoding

    Gets the Encoding in which the output is written.

    Declaration
    public override Encoding Encoding { get; }
    Property Value
    Type Description
    Encoding

    The Encoding specified in the constructor for the current instance, or UTF8Encoding if an encoding was not specified.

    Overrides
    TextWriter.Encoding

    Methods

    Close()

    Closes the current StreamWriter object and the underlying stream.

    Declaration
    public override void Close()
    Overrides
    TextWriter.Close()
    Remarks

    This method overrides Close(). This implementation of Close() calls the Dispose(bool) method passing a true value. You must call Close() to ensure that all data is correctly written out to the underlying stream.Following a call to Close(), any operations on the StreamWriter might raise exceptions. If there is insufficient space on the disk, calling Close() will raise an exception. Flushing the stream will not flush its underlying encoder unless you explicitly call Flush() or Close().

    Dispose(bool)

    Causes any buffered data to be written to the underlying stream, releases the unmanaged resources used by the StreamWriter, and optionally the managed resources.

    Declaration
    protected override void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

    true to release both managed and unmanaged resources; false to release only unmanaged resources.

    Overrides
    TextWriter.Dispose(bool)
    Remarks

    When the disposing parameter is true, this method releases all resources held by any managed objects that this StreamWriter references. This method invokes the Dispose(bool) method of each referenced object.

    Flush()

    Clears all buffers for the current writer and causes any buffered data to be written to the underlying stream.

    Declaration
    public override void Flush()
    Overrides
    TextWriter.Flush()
    Remarks

    This method overrides TextWriter.Flush. Flushing the stream will not flush its underlying encoder unless you explicitly call Flush or Close().

    Exceptions
    Type Condition
    ObjectDisposedException

    The current writer is closed.

    IOException

    An I/O error has occurred.

    Write(char)

    Writes a character to the stream.

    Declaration
    public override void Write(char value)
    Parameters
    Type Name Description
    char value
    Overrides
    TextWriter.Write(char)
    Remarks

    This method overrides Write(char). The specified character is written to the underlying stream unless the end of the stream is reached prematurely.

    WriteLine()

    Writes a line terminator to the text stream.

    Declaration
    public override void WriteLine()
    Overrides
    TextWriter.WriteLine()

    WriteLine(string)

    Writes a string to the stream, followed by a line terminator.

    Declaration
    public override void WriteLine(string value)
    Parameters
    Type Name Description
    string value
    Overrides
    TextWriter.WriteLine(string)
    Remarks

    This overload is equivalent to the Write(string) overload. The line terminator is defined by the CoreNewLine field. This method does not search the specified string for individual newline characters(hexadecimal 0x000a) and replace them with NewLine.

    Implements

    IDisposable

    Extension Methods

    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    In This Article
    Back to top Copyright © 2023 nanoFramework Contributors
    Generated by DocFX