Weird behavior when writing and reading file

前端 未结 2 1690
时光说笑
时光说笑 2021-01-15 10:45

When executing the following code, after the second read, file gets filled with zero until being 4096 bytes large. I can\'t figure out why :

f = open(\"file.         


        
2条回答
  •  温柔的废话
    2021-01-15 11:35

    This is probably related to the filesystem and/or partition. I'm not fully up to speed on the details, but it is likely that 4096 bytes (i.e. exactly 4Kb) is the minimum size of a file in your filesystem and partition. AFAIK, the partition has a block size (often 4096 bytes), and files can only be allocated to whole blocks. So a file is always a multiple of 4096 bytes. I think that some filesystems have a way around this (e.g. reiserfs) by combining small files.

提交回复
热议问题