If I have the integer ""1234" stored in a file, the size of the file when I use the command "ls -l" or "wc -c" is 5. If I have "12345" the size of the file is 6. Basically the number of bytes in a file = (number of individual digits) + 1. Now, I am assuming the "+1" comes from the space it takes to create the name of the file. But why is the rest of the byte count equal to the number of individual characters? Does the file system read the file character by character even we "write an integer" to the file? Elaboration on this would be very helpful.
closed as off-topic by David Richerby, Tom van der Zanden, Raphael♦ Apr 3 '16 at 8:24
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question does not appear to be about computer science, within the scope defined in the help center." – David Richerby, Tom van der Zanden, Raphael
The +1 is for the newline character.
The byte count equals the number of characters, in this case, because each character takes exactly one byte. That need not be true in general (see, e.g., UTF-8), but it is for the example you listed.
You didn't write an integer to the file. You wrote a string -- a sequence of characters, namely the character 1, then the character 2, then 3, then 4, then a newline. Files don't store integers or other types. They store a sequence of bytes. Each character is converted to one or more bytes using an encoding, and then the sequence of bytes is written.