Sử dụng phương pháp File.Delete để xóa một tệp.
Đầu tiên, đặt đường dẫn của tệp bạn muốn xóa.
String myPath = @"C:\New\amit.txt";
Bây giờ, hãy sử dụng phương thức File.Delete để xóa tệp.
File.Delete(myPath);
Sau đây là mã hoàn chỉnh -
Ví dụ
using System;
using System.IO;
public class Program {
public static void Main() {
String myPath = @"C:\New\amit.txt";
Console.WriteLine("Deleting File");
File.Delete(myPath);
}
} Đầu ra
Deleting File