C Sharp Text Writer

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

C# TextWriter

C# TextWriter class is an abstract class. It is used to write text or sequential series of characters into file. It is found in System.IO namespace.

C# TextWriter Example

Let's see the simple example of TextWriter class to write two lines data.

 
  1. using System;  
  2. using System.IO;  
  3. namespace TextWriterExample  
  4. {  
  5.     class Program  
  6.     {  
  7.         static void Main(string[] args)  
  8.         {  
  9.             using (TextWriter writer = File.CreateText("e:f.txt"))  
  10.             {  
  11.                 writer.WriteLine("Hello C#");  
  12.                 writer.WriteLine("C# File Handling by JavaTpoint");  
  13.             }  
  14.             Console.WriteLine("Data written successfully...");  
  15.         }  
  16.     }  
  17. }  

Output:

Data written successfully...

f.txt:

Hello C#
C# File Handling by JavaTpoint