A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C# program to copy content of one file to another file
Q:

C# program to copy content of one file to another file

0

Given a file and we have to copy its content to another file using C# program.

File.Copy()

This is a method of "File class, which is used to copy all data of source file to the destination file.

Syntax:

File.Copy(source_file,dest_file);

Parameter(s):

  1. source_file - From which we are copying data content.
  2. dest_file - In which data is being copied.
  3.  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program

using System;
using System.IO;

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

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

            File.Copy("ABC.TXT", "XYZ.TXT");

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

        }
    }
}

Output

Content of ABC.TXT :
India is a great country.
Content of XYZ.TXT :
India is a great country.

Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program.

In above function, overwriting a file with the same name is not allowed.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now