Text file: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>Jc3s5h
Undid revision 1292696165 by The Anome (talk) Technically true but not idiomatic, and directly contradicts the lead of "Binary file.
 
game_bola
 
Line 16: Line 16:
| uniform_type = public.plain-text
| uniform_type = public.plain-text
| conforms_to = public.text
| conforms_to = public.text
| magic =  
| magic = None
| developer =  
| developer =  
| released =                <!-- {{start date and age|YYYY|mm|dd|df=yes/no}} -->
| released =                <!-- {{start date and age|YYYY|mm|dd|df=yes/no}} -->
Line 33: Line 33:
A '''text file''' (sometimes spelled '''textfile'''; an old alternative name is '''flat file''') is a kind of [[computer file]] that is structured as a sequence of [[line (text file)|lines]] of [[electronic text]]. A text file exists [[Data storage|stored as data]] within a [[computer file system]].
A '''text file''' (sometimes spelled '''textfile'''; an old alternative name is '''flat file''') is a kind of [[computer file]] that is structured as a sequence of [[line (text file)|lines]] of [[electronic text]]. A text file exists [[Data storage|stored as data]] within a [[computer file system]].


In operating systems such as [[CP/M]], where the operating system does not keep track of the file size in bytes, the end of a text file is denoted by placing one or more special characters, known as an [[end-of-file]] (EOF) marker, as padding after the last line in a text file. In modern operating systems such as [[DOS]], [[Microsoft Windows]] and [[Unix-like]] systems, text files do not contain any special EOF character, because file systems on those operating systems keep track of the file size in bytes.
In operating systems such as [[CP/M]], where the operating system does not keep track of the file size in bytes, the end of a text file is denoted by placing one or more special characters, known as an [[end-of-file]] (EOF) marker, as padding after the last line in a text file.<ref>{{Cite web |url=https://itexus.com/eof-end-of-file-what-it-means-and-how-its-used-in-programming/#:~:text=EOF%20is%20not%20a%20physical,NULL%20)%20in%20many%20programming%20languages. |title=EOF: What it Means and How It's Used in Programming |website=Itexus |access-date=5 September 2025}}</ref> In modern operating systems such as [[DOS]], [[Microsoft Windows]] and [[Unix-like]] systems, text files do not contain any special EOF character, because file systems on those operating systems keep track of the file size in bytes.<ref>{{Cite web |url=https://learn.microsoft.com/en-us/windows/win32/fileio/testing-for-the-end-of-a-file |title=Testing for the End of a File |website=Microsoft Learn |publisher=Microsoft |access-date=5 September 2025}}</ref>


Some operating systems, such as [[Multics]], Unix-like systems, CP/M, DOS, the [[classic Mac OS]], and Windows, store text files as a sequence of bytes, with an [[Newline|end-of-line]] [[delimiter]] at the end of each line. Other operating systems, such as [[OpenVMS]] and [[OS/360 and successors|OS/360 and its successors]], have [[record-oriented filesystem]]s, in which text files are stored as a sequence either of fixed-length records or of variable-length records with a record-length value in the record header.  
Some operating systems, such as [[Multics]], Unix-like systems, CP/M, DOS, the [[classic Mac OS]], and Windows, store text files as a sequence of bytes, with an [[Newline|end-of-line]] [[delimiter]] at the end of each line. Other operating systems, such as [[OpenVMS]] and [[OS/360 and successors|OS/360 and its successors]], have [[record-oriented filesystem]]s, in which text files are stored as a sequence either of fixed-length records or of variable-length records with a record-length value in the record header.  
Line 47: Line 47:
A simple text file may need no additional [[metadata]] (other than knowledge of its [[character set]]) to assist the reader in interpretation. A text file may contain no data at all, which is a case of [[zero-byte file]].
A simple text file may need no additional [[metadata]] (other than knowledge of its [[character set]]) to assist the reader in interpretation. A text file may contain no data at all, which is a case of [[zero-byte file]].


== Encoding ==
<!DOCTYPE html>
{{Unreferenced section|date=September 2024}}
<html lang="id">
The [[ASCII|ASCII character set]] is the most common compatible subset of character sets for English-language text files, and is generally assumed to be the default file format in many situations. It covers American English, but for the British [[pound sign]], the [[euro sign]], or characters used outside English, a richer character set must be used. In many systems, this is chosen based on the default [[Locale (computer software)|locale]] setting on the computer it is read on. Prior to UTF-8, this was traditionally single-byte encodings (such as [[ISO-8859-1]] through [[ISO-8859-16]]) for European languages and [[wide character]] encodings for Asian languages.
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Game Bola 2D</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
      background: #f0f0f0;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }
    canvas {
      background: white;
      border: 3px solid #333;
    }
  </style>
</head>
<body>
  <canvas id="gameCanvas" width="800" height="600"></canvas>


Because encodings necessarily have only a limited repertoire of characters, often very small, many are 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. UTF-8 also has the advantage that [[UTF-8#fallback and auto-detection|it is easily auto-detectable]]. Thus, a common operating mode of UTF-8 capable software, when opening files of unknown encoding, is to try UTF-8 first and fall back to a locale dependent legacy encoding when it definitely is not UTF-8.
  <script>
    const canvas = document.getElementById("gameCanvas");
    const ctx = canvas.getContext("2d");
 
    let x = canvas.width / 2;
    let y = canvas.height / 2;
    const radius = 25;
    const speed = 5;
 
    const keys = {};
 
    document.addEventListener("keydown", (e) => (keys[e.key] = true));
    document.addEventListener("keyup", (e) => (keys[e.key] = false));
 
    function update() {
      if (keys["ArrowLeft"]) x -= speed;
      if (keys["ArrowRight"]) x += speed;
      if (keys["ArrowUp"]) y -= speed;
      if (keys["ArrowDown"]) y += speed;
 
      // Batas layar
      if (x - radius < 0) x = radius;
      if (x + radius > canvas.width) x = canvas.width - radius;
      if (y - radius < 0) y = radius;
      if (y + radius > canvas.height) y = canvas.height - radius;
    }
 
    function draw() {
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      ctx.beginPath();
      ctx.arc(x, y, radius, 0, Math.PI * 2);
      ctx.fillStyle = "dodgerblue";
      ctx.fill();
      ctx.closePath();
    }
 
    function gameLoop() {
      update();
      draw();
      requestAnimationFrame(gameLoop);
    }
 
    gameLoop();
  </script>
</body>
</html>


== Formats ==
== Formats ==
Line 84: Line 150:


== See also ==
== See also ==
* [[ASCII]]
* {{Annotated link|ASCII}}
* [[EBCDIC]]
* {{Annotated link|EBCDIC}}
* [[Filename extension]]
* {{Annotated link|Filename extension}}
* [[List of file formats]]
* {{Annotated link|List of file formats}}
* [[Newline]]
* {{Annotated link|Newline}}
* [[Syntax highlighting]]
* {{Annotated link|Syntax highlighting}}
* [[Text-based protocol]]
* {{Annotated link|Text-based protocol}}
* [[Text editor]]
* {{Annotated link|Text editor}}
* [[Unicode]]
* {{Annotated link|Unicode}}


== Notes and references ==
== Notes and references ==
Line 103: Line 169:


[[Category:Text file formats|*]]
[[Category:Text file formats|*]]
[[Category:Computer data]]
[[Category:Computer files]]

Latest revision as of 13:36, 7 November 2025

Template:Short description Template:More citations needed Script error: No such module "Infobox".Template:Template otherScript error: No such module "Check for unknown parameters".

A text file (sometimes spelled textfile; an old alternative name is flat file) is a kind of computer file that is structured as a sequence of lines of electronic text. A text file exists stored as data within a computer file system.

In operating systems such as CP/M, where the operating system does not keep track of the file size in bytes, the end of a text file is denoted by placing one or more special characters, known as an end-of-file (EOF) marker, as padding after the last line in a text file.[1] In modern operating systems such as DOS, Microsoft Windows and Unix-like systems, text files do not contain any special EOF character, because file systems on those operating systems keep track of the file size in bytes.[2]

Some operating systems, such as Multics, Unix-like systems, CP/M, DOS, the classic Mac OS, and Windows, store text files as a sequence of bytes, with an end-of-line delimiter at the end of each line. Other operating systems, such as OpenVMS and OS/360 and its successors, have record-oriented filesystems, in which text files are stored as a sequence either of fixed-length records or of variable-length records with a record-length value in the record header.

"Text file" refers to a type of container, while plain text refers to a type of content.

At a generic level of description, there are two kinds of computer files: text files and binary files.[3]

Data storage

Script error: No such module "Unsubst".

File:CsvDelimited001.svg
A stylized iconic depiction of a CSV-formatted text file

Because of their simplicity, text files are commonly used for storage of information. They avoid some of the problems encountered with other file formats, such as endianness, padding bytes, or differences in the number of bytes in a machine word. Further, when data corruption occurs in a text file, it is often easier to recover and continue processing the remaining contents. A disadvantage of text files is that they usually have a low entropy, meaning that the information occupies more storage than is strictly necessary.

A simple text file may need no additional metadata (other than knowledge of its character set) to assist the reader in interpretation. A text file may contain no data at all, which is a case of zero-byte file.

<!DOCTYPE html> <html lang="id"> <head>

 <meta charset="UTF-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 <title>Game Bola 2D</title>
 <style>
   body {
     margin: 0;
     overflow: hidden;
     background: #f0f0f0;
     display: flex;
     justify-content: center;
     align-items: center;
     height: 100vh;
   }
   canvas {
     background: white;
     border: 3px solid #333;
   }
 </style>

</head> <body>

 <canvas id="gameCanvas" width="800" height="600"></canvas>
 <script>
   const canvas = document.getElementById("gameCanvas");
   const ctx = canvas.getContext("2d");
   let x = canvas.width / 2;
   let y = canvas.height / 2;
   const radius = 25;
   const speed = 5;
   const keys = {};
   document.addEventListener("keydown", (e) => (keys[e.key] = true));
   document.addEventListener("keyup", (e) => (keys[e.key] = false));
   function update() {
     if (keys["ArrowLeft"]) x -= speed;
     if (keys["ArrowRight"]) x += speed;
     if (keys["ArrowUp"]) y -= speed;
     if (keys["ArrowDown"]) y += speed;
     // Batas layar
     if (x - radius < 0) x = radius;
     if (x + radius > canvas.width) x = canvas.width - radius;
     if (y - radius < 0) y = radius;
     if (y + radius > canvas.height) y = canvas.height - radius;
   }
   function draw() {
     ctx.clearRect(0, 0, canvas.width, canvas.height);
     ctx.beginPath();
     ctx.arc(x, y, radius, 0, Math.PI * 2);
     ctx.fillStyle = "dodgerblue";
     ctx.fill();
     ctx.closePath();
   }
   function gameLoop() {
     update();
     draw();
     requestAnimationFrame(gameLoop);
   }
   gameLoop();
 </script>

</body> </html>

Formats

On most operating systems, the name text file refers to a file format that allows only plain text content with very little formatting (e.g., no bold or italic types). Such files can be viewed and edited on text terminals or in simple text editors. Text files usually have the MIME type text/plain, usually with additional information indicating an encoding.

Microsoft Windows text files

DOS and Microsoft Windows use a common text file format, with each line of text separated by a two-character combination: carriage return (CR) and line feed (LF). 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.

On Microsoft Windows operating systems, a file is regarded as a text file if the suffix of the name of the file (the "filename 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.

Most Microsoft Windows text files use ANSI, OEM, Unicode or UTF-8 encoding. What Microsoft Windows terminology calls "ANSI encodings" are usually single-byte ISO/IEC 8859 encodings (i.e. ANSI in the Microsoft Notepad menus is really "System Code Page", non-Unicode, legacy encoding), 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 Microsoft Windows, before the transition to Unicode. By contrast, OEM encodings, also known as 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 DOS applications. "Unicode"-encoded Microsoft Windows text files contain text in UTF-16 Unicode Transformation Format. Such files normally begin with byte order mark (BOM), which communicates the endianness of the file content. Although UTF-8 does not suffer from endianness problems, many Microsoft Windows programs (i.e. Notepad) prepend the contents of UTF-8-encoded files with BOM,[4] to differentiate UTF-8 encoding from other 8-bit encodings.[5]

Unix text files

On Unix-like operating systems, text files format is precisely described: POSIX defines a text file as a file that contains characters organized into zero or more lines,[6] where lines are sequences of zero or more non-newline characters plus a terminating newline character,[7] normally LF.

Additionally, POSIX defines a Template:Vanchor as a text file whose characters are printable or space or backspace according to regional rules. This excludes most control characters, which are not printable.[8]

Apple Macintosh text files

Prior to the advent of macOS, the classic 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".[9] Lines of classic Mac OS text files are terminated with CR characters.[10]

Being a Unix-like system, macOS uses Unix format for text files.[10] Uniform Type Identifier (UTI) used for text files in macOS is "public.plain-text"; additional, more specific UTIs are: "public.utf8-plain-text" for utf-8-encoded text, "public.utf16-external-plain-text" and "public.utf16-plain-text" for utf-16-encoded text and "com.apple.traditional-mac-plain-text" for classic Mac OS text files.[9]

Rendering

When opened by a text editor, human-readable content is presented to the user. This often consists of the file's plain text visible to the user. Depending on the application, control codes may be rendered either as literal instructions acted upon by the editor, or as visible escape characters that can be edited as plain text. Though there may be plain text in a text file, control characters within the file (especially the end-of-file character) can render the plain text unseen by a particular method.

Related concepts

The use of lightweight markup languages such as TeX, markdown and wikitext can be regarded as an extension of plain text files, as marked-up text is still wholly or partially human-readable in spite of containing machine-interpretable annotations. Early uses of HTML could also be regarded in this way, although the HTML of modern websites is largely unreadable by humans. Other file formats such as enriched text and CSV can also be regarded as human-interpretable to some degree.

See also

Notes and references

Template:Reflist

External links

Template:Computer files

  1. Script error: No such module "citation/CS1".
  2. Script error: No such module "citation/CS1".
  3. Script error: No such module "citation/CS1".
  4. Script error: No such module "citation/CS1".
  5. Script error: No such module "citation/CS1".
  6. Script error: No such module "citation/CS1".
  7. Script error: No such module "citation/CS1".
  8. Script error: No such module "citation/CS1".
  9. a b Script error: No such module "citation/CS1".
  10. a b Script error: No such module "citation/CS1".