C# program to copy the content of one file to another file by overwriting the same file name

C# program to copy content of one file to another file by overwriting same file name

Program

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string data;

            Console.WriteLine("Content Before copy:\n");
            data = File.ReadAllText("source/ABC.TXT");
            Console.WriteLine("Content of source/ABC.TXT :\n" + data);

            data = File.ReadAllText("dest/ABC.TXT");
            Console.WriteLine("Content of dest/ABC.TXT :\n" + data+"\n\n\n");

            File.Copy("source/ABC.TXT", "dest/ABC.TXT",true);

            Console.WriteLine("Content After copy:\n");
            data = File.ReadAllText("source/ABC.TXT");
            Console.WriteLine("Content of source/ABC.TXT :\n" + data);

            data = File.ReadAllText("dest/ABC.TXT");
            Console.WriteLine("Content of dest/ABC.TXT :\n" + data);

        }
    }
}

Output

Content Before copy:

Content of source/ABC.TXT :
India is a great country.
Content of dest/ABC.TXT :
Think big, Think beyond.


Content After copy:

Content of source/ABC.TXT :
India is a great country.
Content of dest/ABC.TXT :
India is a great country.

Recent Posts

error: Alert: Content is protected!!