EOF真的存在吗?
当我在 PHP 中使用文件函数时,我会检查 EOF。我想知道 EOF 是否真的存在于文件中。当我创建一个空文本文件时,它显示 0KB。 0KB的文件中怎么存在EOF呢?
When I use file functions in PHP, I check for EOF. I wonder if EOF actually exist in a file. When I create an empty text file, it displays 0KB. How does EOF exist in a file with 0KB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个文件结束控制字符(在 ASCII 字符集中为 CTRL+Z 或 26 或 0x1A),但自 80 年代发布操作系统以来,实际上并不需要它来标记文件结束。所有现代操作系统都将文件大小作为元数据存储在目录结构中(确切的格式取决于文件系统),并且高级文件访问函数将检查文件大小以决定何时向程序员指示 EOF。
如果数据中有文件结尾并且您打开了文本模式翻译(在大多数语言中,这与控制 NL <-> CRLF 转换的设置相同),则文件访问可能会在以下情况下停止:击中 EOF 字符。在二进制模式下,读取将继续进行,直到达到文件大小为止。
There is an end-of-file control character (in the ASCII character set it's CTRL+Z or 26 or 0x1A), but it hasn't actually been needed to mark the end of a file since OSes released in the 80's. All modern OSes store the file size as metadata in the directory structure (exact format depends on filesystem) and high level file access functions will check the file size to decide when to indicate EOF to you, the programmer.
If there is an end-of-file in the data AND you have text-mode translations turned on (in most languages this is the same setting that controls NL <-> CRLF conversions), then the file access may stop when it hits that EOF character. In binary mode, reads will keep going until the file size is hit.
在现代文件系统中,磁盘上没有实际的 EOF 字符。它在某些文件读取函数中通过返回 4 字节值而不是 1 字节值来实现,但大多数函数不使用该概念。
In modern filesystems there is no actual EOF character on the disk. It's implemented in some file reading functions by returning a 4 byte value instead of a 1 byte value, but most functions don't use the concept.
它不存在..但文件大小确实存在,这就是你知道 eof 在哪里的方式
it doesn't exist.. but file size does, and that's how you know where is eof