Given a file and we have to copy its content to another file by overwriting same file name 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, here we are using an extra parameter to over write the file.
Syntax:
File.Copy(source_file,dest_file,overWrting);
Parameter(s):
- source_file - From which we are copying data content.
- dest_file - In which data is being copied.
- overWrting - It is a Boolean flag, true allowed overwriting.
-
Program
Output
Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program.
Here program is copying the content of 'source/ABC.TXT' to 'dest/ABC.TXT' and In above Copy method there is a third Boolean parameter is used to allow/deny overwriting content in case of same file name.