C# Program to Copy the Contents of One File to Another File

This is a C# Program to copy the contents from one file to another file.

Problem Description

This C# Program Copies the Contents from one File to another File.

Problem Solution

Here File.Copy method is used to copy the contents of one file to another.

Program/Source Code

Here is source code of the C# Program to Copy the Contents from one File to another File. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Print the Sum of all the Multiples of 3 and 5
 */
using System;
using System.IO;
class Program
{
    static void Main()
    {
        File.Copy("sri.txt", "srip.txt");
        Console.WriteLine(File.ReadAllText("sri.txt"));
        Console.WriteLine(File.ReadAllText("srip.txt"));
        Console.Read();
    }
}
Program Explanation

This C# program is used to copy the content from one file to another file. Here File.Copy method is used to copy the contents of one file to another. The ReadAllText() method is used to open a text file and read all lines of the file, and then close the file.

advertisement
advertisement
Runtime Test Cases
 
Contents of File S
Contents of File S

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.