In c#, TextWriter is a class of System.IO namespace, and it is useful to write a text or sequential series of characters in the file. The TextWriter is an abstract class, and it writes the characters to streams and strings.
Now, we will see how to use TextWriter class in c# to write a text or sequential series of characters in the file with examples.
Following is the example of writing a text or sequential series of characters in a file using the TextWriter object in c#.
If you observe the above example, we imported a System.IO namespace to access File & TextWriter objects to delete, create and write a text to file.
When we execute the above example, it will create a new “Test.txt” file in the D drive with the required text as shown below.
This is how we can create, delete and add text to files using File & TextStream objects in c#.