TextWriter CLASS

A text writer that writes text to a stream.

This class is not thread-safe and must be protected by lock when used in a multi-threaded context.

Parent Class

All Members


TypeNameSignature
constructorTextWriterpublic TextWriter(System.IO.Stream)
constructorTextWriterpublic TextWriter(System.IO.Stream, string, int, bool)
methodclosepublic void close()
methodflushpublic void flush()
methodsetAutoFlushpublic void setAutoFlush(bool)
methodwritepublic void write(string)
methodwritelnpublic void writeln(string)

Constructors


public TextWriter(Stream stream)

Create a TextWriter to write text to the specified stream. Use default buffer size (8K) and default chatset (ASCII). Also set autoFlush to true.

Parameters

  • stream A stream to write the text to. Must be writable.

Throws


public TextWriter(Stream stream, string charset, int bufferSize, bool autoFlush)

Create a TextWriter to write text to the specified stream.

Parameters

  • stream A stream to write the text to. Must be writable.
  • charset The charset to use when converting the read bytes to string. Charset names should have been registered by RFC 2278: IANA Charset Registration Procedures.
  • bufferSize The initial buffer size. Will be set to 1 if it's less than 1. The caller may use a bigger value if the intention is to write large chunks of text. If the argument passed in is less than 2 MB, the TextWriter instance may dynamically expand the size as it sees fit, without going beyond an upper limit of 4 MB.
  • autoFlush True to flush everytime any of write methods is called; false to only flush when the buffer is full or the writer is to be closed.

Throws


Methods


public void close()

Flush the buffer and close the underlying stream.


public void flush()

Flush the writer by writing all bytes which are so far buffered into the target stream.


public void setAutoFlush(bool autoFlush)

Set whether to automatically flush everytime any of write methods is called.

Parameters

  • autoFlush True to flush everytime any of write methods is called; false to only flush when the buffer is full or the writer is to be closed.

public void write(string text)

Write the text to the stream.

Parameters

  • text The text to write.

public void writeln(string text)

Write the text, followed by an OS-specific line separator, to the stream.

Parameters

  • text The text to write.