Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I create a new blank .txt file and file size is 0 bytes.

Then I just add one character to the file and file size is 1 byte.

1000 byte file size could mean that it has 1000 characters?

share|improve this question
add comment

migrated from stackoverflow.com Dec 3 '09 at 16:03

This question came from our site for professional and enthusiast programmers.

5 Answers

Operating systems (windows, linux etc.) try to divide hard disk volume into pieces (technically called “clusters”), every one of which usually can contain many bytes of data, say 1024 bytes per cluster. Therefore, even if your file contains only 1 byte, the file will still occupy one cluster. If a file contains 1025 bytes, it will occupy two clusters. … and that’s why.

share|improve this answer
add comment

When a file allocates disk space it does so in chunks based on the configuration used when the disk was formatted. Regardless of the amount of actually data (file size) the chunks need to be allocated to accommodate all of the data. For example using your example: An empty file (zero bytes) requires no chunks to be allocated. As soon as you add a single byte the OS needs to allocate a chunk to accommodate that data. On my XP system that seems to be 4KB. Therefore a file size of 1 byte will take up 4KB of space on the disk. If that chunk is filled to 1 byte over 4KB then another chunk will be allocated to make the size on disk equal to 8KB.

share|improve this answer
add comment

I'm not sure what the actual question is here. Do you mean that it's saying it's 1KB (not 1 byte, but 1 kilobyte)? It's probably a case of windows rounding up to the nearest kilobyte. The file is almost certainly only using a byte of disk space, but XP measures file sizes in KB so it rounds up.

It doesn't round to 0 even though it's far closer to 0 than 1 because 0 implies the file is empty.

share|improve this answer
add comment

You have to know the difference between file size and disk usage. A file can have little content but use a lot more disk space.

share|improve this answer
add comment

Depends on the encoding used. If you use ANSI enconding, then yes. It is one byte per char used. If you use UTF-8, for instance , you use more thant 1 byte (more like 3 bytes per character).

share|improve this answer
2  
UTF-8 for ASCII also uses just one byte per code point. –  Joey Dec 3 '09 at 16:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.