Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Chương trình C# lấy thời gian truy cập cuối file

Thuộc tính FileInfo.LastAccessTime trả về lần cuối file được đọc.

Ví dụ

using System.IO;
using System;

public class Program
{
    public static void Main()
    {
        using (StreamWriter sw = new StreamWriter("quiz.txt"))
        {
            sw.WriteLine("Quizzes!");
        }
        FileInfo file = new FileInfo("quiz.txt");
        DateTime dt = file.LastAccessTime;
        Console.WriteLine(dt);
    }
}

Kết quả

9/5/2018 5:21:43 AM

Chú ý: Hệ điều hành có thể tắt cập nhật LastAccessTime để tăng hiệu năng (Windows mặc định tắt từ Vista).