Skip to content

9618 · 10.3

Files

Variables store data while a programme is running, but what happens when it closes? Files act as a permanent storage, like a digital filing cabinet, allowing your programme to save its work and retrieve it later.

Need to know

What you need to know

  • **File:** A named collection of data stored on secondary storage.
  • **Record:** A line or structured block of data representing one item (e.g., '101,Bob,17').
  • **Field:** A single data item within a record (e.g., 'Bob').

Explanation

Your Programme's Long-Term Memory

  1. Choose your action: Decide if you need to read existing data, create a new file, or add to an existing one. This determines the 'mode' (READ, WRITE, APPEND).
  2. Open the file: Use the OPENFILE command with the filename and your chosen mode. This gives your program access.
  3. Process the data: Use a loop with READFILE to get data from the file, or use WRITEFILE to save data to it.
  4. Close the file: Use the CLOSEFILE command. This is crucial to save changes and release the file for other programs to use.