Like StreamWriter there are other classes that are derived from the TextWriter class and provide the implementation for the members of TextWriter. Please find below the list of those derived classes with the help of which we can work with TextWriter:. Generic; using System. Linq; using System. Text; using System. Tasks; using System. WriteLine ex. TextWriter is used to write text or sequential series of characters to a file.
A class derived from the TextWriter class needs to provide implementation to any of the members of the TextWriter. Write methods of TextWriter with primitive data types as parameters write out values as strings. This is a guide to TextWriter in C. Here we discuss how TextWriter works in C along with the examples and outputs. You may also look at the following article to learn more —. Submit Next Question. By signing up, you agree to our Terms of Use and Privacy Policy.
The TextReader and TextWriter are base classes. This class defines members that allow derived types to write textual data to a given character stream. Let us see some of the main members of the abstract class TextWriter. Before we move into writing to a text file we have to know about "FileInfo" class. What is FileInfo? In the framework of. NET , the system. IO namespace is the region of the base class libraries devoted to file-based input and output services.
File Info is one of the core type of System. IO Namespace. The function of the FileInfo is to encapsulate a number of details regarding existing files on your hard drive size,file attributes,creating time,etc. Let us move to example. In this example in the Writetextfile class I create a file named "Arungg. After creating the text file using the CreateText method, I get a StreamWriter and write some textual data to the newly created text file. We can also add numeric data into the text file.
CreateText ; Tex. WriteLine "Arungg has launced another article" ; Tex. WriteLine "csharpheaven is the new url for c-sharpcorner" ; Tex. Write Tex.
Text namespace. UTF32, StreamWriter. Write method StreamWriter. Write method writes a char, string of chars, or a string to the steam. The following code snippet creates and writes different content to the stream. WriteLine method StreamWriter.
WriteLine method writes a string to the next line to the steam. The following code snippet creates and writes different author names to the stream. WriteLine "C Corner Authors" ; writer. WriteLine "Monica Rathbun" ; writer. WriteLine "Vidya Agarwal" ; writer. WriteLine "Mahesh Chand" ; writer. WriteLine "Vijay Anand" ; writer. WriteAsync method StreamWriter. WriteAsync method writes a char, string of chars, or a string to the stream asynchronously.
The method returns a Task that represents the asynchronous write operation. GetChars encoder. WriteAsync chars, 0, chars. WriteLineAsync method StreamWriter.
WriteLineAsync method writes a char or char array to a new asynchronously. The following code snippet creates and writes a new line for each char to the stream.
WriteLineAsync 'm' ; await writer.
0コメント