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