Home  >  Article  >  Backend Development  >  C# program to copy existing files

C# program to copy existing files

WBOY
WBOYforward
2023-09-08 18:21:161940browse

C# 程序复制现有文件

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);

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete