首頁  >  文章  >  後端開發  >  C# 程式複製現有文件

C# 程式複製現有文件

WBOY
WBOY轉載
2023-09-08 18:21:161889瀏覽

C# 程序复制现有文件

使用 File.Copy 方法複製現有檔案。

新增要複製的檔案的路徑。

String myPath = @"D:\one.txt";

現在將上述檔案複製到以下檔案中 −

String myPath = @"D:\one.txt";

使用 File.Copy 方法,同時指定原始檔案和目標檔案。

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

以上是C# 程式複製現有文件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除