FileInfo类型具有Length属性,该属性确定文件具有多少字节。
首先,设置文件-
FileInfo file = new FileInfo("D:\\new");现在使用Length属性-
file.Length
这是完整的代码-
using System;
using System.Linq;
using System.IO;
class Program {
static void Main() {
FileInfo file = new FileInfo("D:\\new");
long res = file.Length;
Console.WriteLine("Bytes: "+res);
}
}输出结果
以下是输出-
3259244