用 C# 獲取檔案中的位元組數


FileInfo 型別具有一個 Length 屬性,它用於確定一個檔案有多少位元組。

首先,設定檔案 −

FileInfo file = new FileInfo("D:\
ew");

現在使用 Length 屬性 −

file.Length

以下是完整程式碼 −

示例

using System;
using System.Linq;
using System.IO;
class Program {
   static void Main() {
      FileInfo file = new FileInfo("D:\
ew");       long res = file.Length;       Console.WriteLine("Bytes: "+res);    } }

輸出

以下是輸出 −

3259244

更新於:2020 年 4 月 7 日

376 次瀏覽

開啟 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.