Copy an existing file using the File.Copy method.
Add the path of the file to be copied.
String myPath = @"D:\one.txt";
Now copy the above file into the following file −
String myPath = @"D:\one.txt";
Use the File.Copy method, specifying both the source file and the destination file.
File.Copy(myPath,newpath);
using System; using System.IO; public class Program { public static void Main() { String myPath = @"D:\one.txt"; // the file will get copied here String newpath = @"D:\two.txt"; // copying file File.Copy(myPath,newpath); } }
The above is the detailed content of C# program to copy existing files. For more information, please follow other related articles on the PHP Chinese website!