C
C
CityzenUNDEAD2022-02-22 13:16:54
.NET
CityzenUNDEAD, 2022-02-22 13:16:54

Why is the file size smaller than expected?

Good afternoon!
I'm trying to get the weight of a random file in 2 ways.

Method 1.

string filePath = @"C:\Users\User\Desktop\new.txt";
FileInfo fileInfo = new FileInfo(filePath);
           
Console.WriteLine(fileInfo.Length);


Method 2.
string filePath = @"C:\Users\User\Desktop\new.txt";
using(FileStream fs = new FileStream(filePath, FileMode.Open)) 
            {
                byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(filePath);
                Console.WriteLine($"Вес массива байтов {fileBytes.Length}");
            }


Why is the file size different?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-02-22
@Sing303

In the first case you get the size of the file
In the second case you get the length of the string filePath in bytes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question