Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

รับจำนวนไบต์ในไฟล์ใน C #


ประเภท FileInfo มีคุณสมบัติความยาวที่กำหนดจำนวนไบต์ของไฟล์

ขั้นแรก ตั้งค่าไฟล์ −

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

ตอนนี้ใช้คุณสมบัติความยาว -

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