Why should text files end with a newline?

后端 未结 18 1638
栀梦
栀梦 2020-11-21 22:56

I assume everyone here is familiar with the adage that all text files should end with a newline. I\'ve known of this \"rule\" for years but I\'ve always wondered — why?

18条回答
  •  滥情空心
    2020-11-21 23:38

    Presumably simply that some parsing code expected it to be there.

    I'm not sure I would consider it a "rule", and it certainly isn't something I adhere to religiously. Most sensible code will know how to parse text (including encodings) line-by-line (any choice of line endings), with-or-without a newline on the last line.

    Indeed - if you end with a new line: is there (in theory) an empty final line between the EOL and the EOF? One to ponder...

提交回复
热议问题