Text file

From Wikipedia, the free encyclopedia

Jump to: navigation, search
For Texting Language, see SMS language.
A stylized iconic depiction of a CSV-formatted text file.
A stylized iconic depiction of a CSV-formatted text file.

A text file is a generic description of a kind of computer file in a computer file system.[1] At this generic level of description, there are two kinds of computer files: 1) text files; and 2) binary files.[2] This broad two-level distinction is widely recognized and applied in computing, even though it can be misleading, and subject to differening interpretation.[3][4]

The most common basis for distinguishing text files from binary files depends on the how the underlying stored information is ultimately interpreted and processed by the operating system and associated programs.[5] Text files are usually interpreted as consisting solely of characters from a recognized character set. Well-known character sets include the ASCII character set and the Unicode character set.[6]

There is a distinction between plain text, containing only text, newline codes and an end of file marker, and structured text, which may contain a lot of additional information, such as start and end marks of bold, italic, colored text, start and end of paragraphs, chapter headers and numbered lists.[citation needed] This extra information is not essential for the understanding of the text, but, with a proper program, it regulates the display of the text so to make its reading much easier.[citation needed] Without such a proper program, the text can be extracted from the structured text and still be understood.[citation needed]

Previously a lot of structured text formats were constructed for every text editor or word processor there ever was, so that document format (structured text) incompatibility was a major headache.[citation needed] The modern trend is however towards XML based structured text formats, which opens the format for inspection and easier conversion.[Who?][vague]

Contents

[edit] Components

Text files are files where most bytes (or short sequences of bytes) represent ordinary readable characters such as letters, digits, and punctuation (including spaces), and include some control characters such as tabs, line feeds and carriage returns. This simplicity allows a wide variety of programs to display their contents.

[edit] Cryptography

The similar term plaintext is most commonly used in a cryptographic context and refers to unencrypted data; however, this unencrypted data does not necessarily have to be a text file. The similarity between the terms "plaintext" and "text file" sometimes causes confusion, especially among those new to computers, cryptography, or data communications.

[edit] Encoding

Main article: character encoding

Generally, a text file contains characters in an ASCII-based encoding, or much less commonly an EBCDIC-based encoding, without any embedded information such as font information, hyperlinks or inline images. Text files are often encoded in an extension of ASCII; these include ISO 8859, EUC, a special encoding for Windows, a special Mac-Roman encoding for Mac OS, and Unicode encoding schemes (common on many platforms) such as UTF-8 or UTF-16.

[edit] Software use

Although text files are often meant for humans to read, they are also commonly used for data storage by computer programs. Text files have some advantages even for data storage because they avoid certain problems with binary files, such as endianness, padding bytes, or differences in the number of bytes in a machine word. Further, when data corruption occurs in a file used for data storage, it is far easier for a human to fix if it is a text file. As a bonus, it may be easier for the program to recover from the error, because text files are pretty verbose, while binary files are usually compact (it's said that text files have a low entropy rate). Damaging an amount of a text file destroys little information; damaging the same amount of a binary file destroys more information.

A large drawback of plain text files is that there is no way for a program to reliably determine what encoding is used. A text editor may save its text file in UTF-8, but a compiler might expect its input in ISO 8859. Trying to compile the UTF-8 text file would cause confusion and errors. Some text formats (such as XML) have an in-band mechanism for specifying the encoding of the document, but most text files have no such mechanism. Some programs go to great lengths to "guess" the encoding by looking for patterns in the text file, but this guessing procedure is very difficult to specify correctly for all cases (see AI-complete).

[edit] Formats

[edit] MIME

Text files usually have the MIME type "text/plain", usually with additional information indicating an encoding. Prior to the advent of Mac OS X, the Mac OS system regarded the content of a file (the data fork) to be a text file when its resource fork indicated that the type of the file was "TEXT". Under the Windows operating system, a file is regarded as a text file if the suffix of the name of the file (the "extension") is "txt". However, many other suffixes are used for text files with specific purposes. For example, source code for computer programs is usually kept in text files that have file name suffixes indicating the programming language in which the source is written.

[edit] ASCII

The ASCII standard allows ASCII-only plain text files (unlike most other file types) to be freely interchanged and readable on Unix, Macintosh, Microsoft Windows, DOS, and other systems. These differ in their preferred line ending convention (see Newline) and their interpretation of values outside the ASCII range (their character encoding).

[edit] Other formats

Plain text is often used as a readable representation of other data that is not itself purely textual: for example, a formatted webpage is not plain text, but its HTML source is. Similarly, source code for computer programs is usually stored in text files, but is compiled into a binary form for execution.

[edit] .txt

.txt is a filename extension for files consisting of text with very little formatting (ex: no bolding or italics). This kind of text format is also called a plain text file to differentiate them from other kinds of binary files, which, at the time the distinction was made, were not supposed to have human readable text. The precise definition of the .txt format is not specified, but typically matches the format accepted by the system terminal or simple text editor. Files with the .txt extension can easily be read or opened by any program that reads text and, for that reason, are considered universal (or platform independent).

[edit] Plain text versus .txt

It should be noted that not all systems use the .txt extension when creating plain text files. In particular, on Unix systems, where extensions are entirely optional, it's common to see text files with no extension at all, the most prominent example being the README file, present in many software packages. However, there's no difference between a plain text file with no extension and a .txt file. The term "plain text" is attributed to the contents of the file, while the term ".txt" is attributed to the file metadata (i.e. the extension).

[edit] Plain text variations

Since plain text is not a formally defined standard, the definition of the format of a plain text file is rather loose. The principle differences are in character sets and character encodings, and conventions about formatting characters semantics.

The ASCII character set is the most common format for English-language text files, and is generally assumed to be the default file format in many situations. For accented and other non-ASCII characters, it is necessary to choose a character encoding. In many systems, this is chosen on the basis of the default locale setting on the computer it is read on. Common character encodings include ISO 8859-1 for many European languages, and BIG5 for Chinese.

Because many encodings have only a limited repertoire of characters, they are often only usable to represent text in a limited subset of human languages. Unicode is an attempt to create a common standard for representing all known languages, and most known character sets are subsets of the very large Unicode character set. Although there are multiple character encodings available for Unicode, the most common is UTF-8, which has the advantage of being backwards-compatible with ASCII: that is, every ASCII text file is also a UTF-8 text file with identical meaning.

[edit] Formatting characters

If one is using an old Macintosh, then the newline command is associated to the ASCII character number 13. If one is using Unix, then the ASCII character is number 10. If, instead, the person is using an IBM Mainframe, then he or she would be using EBCDIC format and next line would be number 15.

[edit] Standard Windows .txt files

Microsoft MS-DOS and Windows use a common text file format, with each line of text separated by a two character combination: CR and LF, which have ASCII codes 13 and 10. It is common for the last line of text not to be terminated with a CR-LF marker, and many text editors (including Notepad) do not automatically insert one on the last line.

Most Windows text files use a form of ANSI, OEM or Unicode encoding. What Windows terminology calls "ANSI encodings" are usually single-byte ISO-8859 encodings, except for in locales such as Chinese, Japanese and Korean that require double-byte character sets. ANSI encodings were traditionally used as default system locales within Windows, before the transition to Unicode. By contrast, OEM encodings, also known as MS-DOS code pages, were defined by IBM for use in the original IBM PC text mode display system. They typically include graphical and line-drawing characters common in full-screen MS-DOS applications. Newer Windows text files may use a Unicode encoding such as UTF-16LE or UTF-8.

[edit] Notes and references

  1. ^ Lewis, John (2006). Computer Science Illuminated. Jones and Bartlett. ISBN 0763741493. 
  2. ^ (Lewis 2006)
  3. ^ (Lewis 2006 p. 354)
  4. ^ The distinction between "text files" and "binary files" can be misleading, because (ultimately) all files in a binary computer file system are stored as binary digits (or bits). The only meaningful distinction arises in how those bits are interpreted and processed by the operating system and any associated programs.
  5. ^ (Lewis 2005)
  6. ^ (Lewis 2005)

[edit] See also

[edit] External links

Personal tools