获取C#文件中的字节数
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
