Writing into a file using WriteAllText() in C#

We can use File.WriteAllText(Filepath) for writing the content to a file.
Remember, the previous content will be no more and the new content will be written by the File.WriteAllText().

using System;
using System.IO;

namespace forgetCode
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "D:\\test.txt";
            if (File.Exists(path))
            {
                Console.WriteLine("Please enter new content for the file:");
                string newContent = Console.ReadLine();
                File.WriteAllText(path, newContent);
            }

          
        }
    }
}



Output:
The content will be written newly (Deleting previous content) to the mentioned path.

..