Xóa một tập tin bằng phương thức File.Delete trong CSharp? (How to delete a file with File.Delete method in CSharp?)


Bài viết này tôi sẽ hướng dẫn cách xóa một tâp tin bằng phương thức File.Delete() trong ngôn ngữ lập trình C#.





File.Delete()

Là một trong những phương thức cơ bản của lớp File(class file) được sử dụng để xóa một tập tin theo một đường dẫn được chỉ định.


Cú pháp - Syntax

public static void Delete(
    string path
)


Ví dụ - Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
// @author: BUI NGOC SON
// @web: vnlives.net

namespace CreateFile
{
    class Program
    {
        static void Main(string[] args)
        {

            string path_01 = "D:/vnlives_file_01";
            System.IO.File.Create(path_01);

            string path_02 = "D:/vnlives_file_02.txt";
            System.IO.File.Create(path_02);

            string path_03 = "D:/vnlives_file_03.csv";
            System.IO.File.Create(path_03);

            Console.WriteLine("File created successfully. - " + path_01);
            Console.WriteLine("File created successfully. - " + path_02);
            Console.WriteLine("File created successfully. - " + path_03);

            Console.ReadLine();

        }
    }
}


Kết quả - Result














No comments:

Post a Comment