Home  >  Article  >  Backend Development  >  C# Get the number of bytes of a file

C# Get the number of bytes of a file

王林
王林forward
2023-09-14 12:33:021195browse

C# 获取文件的字节数

The FileInfo type has a Length property that determines how many bytes the file is.

First, set up the file -

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

Now use the length attribute -

file.Length

Here is the complete code -

Example

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);
   }
}

Output

The following is the output-

3259244

The above is the detailed content of C# Get the number of bytes of a file. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete