C# Program to Copy Content of One File to Another File by Overwriting Same File Name

You are currently viewing C# Program to Copy Content of One File to Another File by Overwriting Same File Name

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

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.

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply