The WriteAllText creates a new file, writes the contents to the file and then closes the file. If a file already exists, then this method overwrites it. The ReadAllText opens a text file, reads all lines of the file into a string, and then closes the file.
string fileName = @"C:\Temp\Mahesh.txt"; if (!File.Exists(fileName)){ string startText = "Here is a file content" + Environment.NewLine; File.WriteAllText(fileName, startText); File.WriteAllText(fileName, "Add more content \n");}string appendText = "New appened text" + Environment.NewLine;File.AppendAllText(fileName, appendText);string data = File.ReadAllText(fileName);Console.WriteLine(data)
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: