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

更新日期: 2020 年 6 月 23 日

830 次瀏覽

開啟您的職業生涯

完成課程,獲得認證

開始吧
廣告