Introduction
A text file holds characters and nothing else: no fonts, no styles, no pictures. Every operating system can open one, and it is the simplest way to keep notes, logs and data that people need to read. What a text file does depend on is how its characters were turned into bytes, its encoding, and how its lines end.
Structure
A text file has no header and no structure beyond its lines. Today most text is UTF-8, which stores ASCII characters as single bytes and everything else as two to four bytes. Older files may use a legacy code page such as Windows-1252, and a few use UTF-16. The file itself does not say which encoding it uses, except when it starts with a byte order mark.
| First bytes | Meaning |
|---|---|
EF BB BF | UTF-8 with a byte order mark |
FF FE | UTF-16, little-endian |
FE FF | UTF-16, big-endian |
Lines end with a line feed (0A) on Linux and macOS, and with a carriage
return and line feed (0D 0A) on Windows. Classic Mac OS used a carriage
return (0D) alone.
Links
Software
- Notepad (Windows, built in)
- TextEdit (macOS, built in)
- Notepad++ (Windows)
- Visual Studio Code (Windows, macOS, Linux)
- Sublime Text (Windows, macOS, Linux)
- BBEdit (macOS)
- Vim (Windows, macOS, Linux)
- GNU Emacs (Windows, macOS, Linux)
Developers
Reference
- The Unicode Standard, Unicode Consortium
- RFC 3629: UTF-8