且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

EOF实际上存在吗?

更新时间:2023-08-21 20:11:22

文件尾有控制字符(ASCII字符)设置为CTRL + Z或26或0x1A),但自从80年代发布操作系统以来,实际上并不需要它来标记文件的结尾。所有现代的操作系统都将文件大小作为元数据存储在目录结构中(确切格式取决于文件系统),高级文件访问功能将检查文件大小,以决定何时向程序员(即程序员)指示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.

如果数据中有文件结尾并且您已打开文本模式转换(在大多数语言中,这是控制NL<-> CRLF转换的相同设置),则碰到该EOF字符时,文件访问可能会停止。在二进制模式下,读取将继续进行,直到达到文件大小为止。

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.