How to calculate the files size. | Sololearn: Learn to code for FREE!


How to calculate the files size.

Let's say I'm going to create a certain file with a certain amount of content. How can I calculate the size of the file before creating it? The content will be plain text so is the file size just the amount of bytes the text has?

5/18/2018 11:09:57 PM

Toni Isotalo

3 Answers

New Answer


well yes, but operating systems have an offset of saved bytes allocated (thats why some files are shown to be larger than they should be. reason why Windows shows 'size' and 'size on disk') just in case the file size has to increase suddenly.


May be it is related to the character encoding we like to use in our text file.. If it is on ASCII, each character takes one byte or less so that we can calculate the file size.. If it is on UNICODE, the file size varies.. for more information refer this stack overflow post


Hello Toni! See the c++ lesson, and look the foolowing topic"sizeof an Array" they talk about the sizeof () function. Remind : this Array category type minimum size boolean bool 1 byte character char 1 byte integer int 2 bytes and so on Good luck!! stephan (France)