Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

โปรแกรม 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);
   }
}