📜  c# 检查文件是否有内容 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:56.538000             🧑  作者: Mango

代码示例1
public static bool IsTextFileEmpty(string fileName)
{
    var info = new FileInfo(fileName);
    if (info.Length == 0)
        return true;

    // only if your use case can involve files with 1 or a few bytes of content.
    if (info.Length < 6)
    {
        var content = File.ReadAllText(fileName);   
        return content.Length == 0;
    }
    return false;
}