在这种情况下,为什么计算文件大小时要多1个字节? [英] In this case, why 1 byte extra when computing the file size?

查看:106
本文介绍了在这种情况下,为什么计算文件大小时要多1个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在通过GUI(alt + enter)在Ubuntu 12.10以及在终端(ls -l)中创建文本文件之后,我做了以下观察.

I made this following observations after making a text file on Ubuntu 12.10 through GUI (alt+enter) as well as in Terminal (ls -l).

  • 文件为空时:文件大小= 0字节.
  • 一个字符时:文件大小= 2个字节.
  • 当两个字符:文件大小= 3个字节时.

为什么当文件仅包含一个字符时额外增加1个字节,我知道这不是因为文件结尾,因为当我编写ac程序时,循环在到达文件结尾时终止,并且给了我相同的结果结果,所以显然这不算什么,那是什么?

Why 1 byte extra when the file just contains one character, i know this is not because of End-Of-File because when i wrote a c program the loop terminated when it reached End-Of-File and it gave me the same results, so obviously this doesn't count, then what is it?

但是在Windows上,当文件包含一个字符时,文件大小仅为1个字节,这是正常的.这些东西背后是什么东西?

But on windows when the file contained one character the file size was just 1 byte, it was normal. What are the things behind all this stuffs?

推荐答案

这是由于文本编辑器所引起的.您必须已按下额外的终止字符,例如换行符.

It's due to text editor you are getting this. YOu must have pressed extra terminating character such as newline.

如果您想要文件中1个字符的 1字节大小.

If you want 1 byte size for 1 character in a file.

只需在您的终端上这样做.

Just do like this on you terminal.

#cat > file // create a file for input
x{CTRL+D}  // after inputting one character 'x' , press CTRL+D twice
           // one for terminating file and one for killing the cat process.

#ls -l  // list the file

您将获得正好 1 字节的文件大小.

You will get exactly 1 byte file size.

尝试一下.(它正在我的系统Ubuntu 11.04上运行)

Try it. (It's working on my system Ubuntu 11.04)

这篇关于在这种情况下,为什么计算文件大小时要多1个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆