C# TextWriter Tutorial with Programming Examples

In this chapter you will learn:
  1. What is TextWriter Class?
  2. How to use it in C# Programming?
The TextWriter class represents a writer that can write sequential series of characters. You can use this class to write text in a file. It is an abstract base class of StreamWriter and StringWriter, which write characters to streams and string respectively.

Programming Example:  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace TextWriter_class
{
    class Program
    {
        static void Main(string[] args)
        {
            string [email protected]"D:\csharpfile.txt";
            using (TextWriter writer = File.CreateText(file))
            {
                writer.WriteLine("Hello TextWriter!");
                writer.WriteLine("File Handling Tutorial");
            }
            Console.WriteLine("Entry stored successfull!");
            Console.ReadKey();
        }
    }
}

Output
Entry stored successfull!
_

Summary

In this chapter you learned how to use TextWriter class in File Handling. Next, you will learn how to read file using TextReader class.

More Articles

 

Share your thought



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.