image
image
image

AppendAllText()

image

Instead of overwriting the already existing text, you can append the text at the end of the file. To do so, you can use the AppendAllText() method. Take a look at the following script:

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace MyProgram

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Enter the content you want to write to file:");

string text = Console.ReadLine();

File.AppendAllText("D:/myfile2.txt", text);

Console.ReadLine();

}

}

}

In the script above, the text entered by the user is appended at the end of the already existing text in “myfile2.txt”.