.NET Framework Class Library  

TextWriter Class

Represents a writer that can write a sequential series of characters. This class is abstract.

For a list of all members of this type, see TextWriter Members.

System.Object
   System.MarshalByRefObject
      System.IO.TextWriter
         System.CodeDom.Compiler.IndentedTextWriter
         System.IO.StreamWriter
         System.IO.StringWriter
         System.Web.HttpWriter
         System.Web.UI.HtmlTextWriter

[Visual Basic]
<Serializable>
MustInherit Public Class TextWriter
   Inherits MarshalByRefObject
   Implements IDisposable
[C#]
[Serializable]
public abstract class TextWriter : MarshalByRefObject, IDisposable
[C++]
[Serializable]
public __gc __abstract class TextWriter : public
   MarshalByRefObject, IDisposable
[JScript]
public
   Serializable
abstract class TextWriter extends MarshalByRefObject
   implements IDisposable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

Remarks

TextWriter is the abstract base class of StreamWriter and StringWriter, which write characters to streams and strings, respectively. Create an instance of TextWriter to write an object to a string, write strings to a file, or to serialize XML. You can also use an instance of TextReader to write text to a custom backing store using the same APIs you would use for a string or a stream, or to add support for text formatting.

All the Write methods of TextWriter having primitive data types as parameters write out the values as strings.

By default, a TextWriter is not thread safe. See TextWriter.Synchronized for a thread-safe wrapper.

A derived class must minimally implement the TextWriter(Char) method in order to make a useful instance of TextWriter.

The following table lists examples of other typical or related I/O tasks.

To do this... See the example in this topic...
Create a text file. Writing Text to a File
Write to a text file. Writing Text to a File
Read from a text file. Reading Text from a File
Append text to a file. Opening and Appending to a Log File

File.AppendText

FileInfo.AppendText

Get the size of a file. FileInfo.Length
Get the attributes of a file. File.GetAttributes
Set the attributes of a file. File.SetAttributes
Determine if a file exists. File.Exists
Read from a binary file. Reading and Writing to a Newly Created Data File
Write to a binary file. Reading and Writing to a Newly Created Data File

Requirements

Namespace: System.IO

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET

Assembly: Mscorlib (in Mscorlib.dll)

See Also

TextWriter Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File | Basic File I/O | Reading and Writing to a Newly Created Data File