Given text, and we have to write it into a file using C# program.
File.WriteAllText()
This is a static method of "File" class, which is used to write all text (passed as an argument) in a file. Note: If the file does not exist at specified location, this method creates file first and then write all text to the file.
Syntax:
void File.WriteAllText(path, content);
Parameters:
- path - Filename with its location.
- content - Text to be written into file.
-
Program:
Output
Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program.