0984

File Handling

Programming · 4 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 3% of your exam marks.

stable
Rare
Stable3%

OPENFILE, READFILE, WRITEFILE, CLOSEFILE pseudocode operations appear occasionally.

Every file that has been opened must be closed before the program ends. Forgetting CLOSEFILE can lose data or corrupt the file.

When a program writes to a file, the operating system does not always send the data straight to the disk. Instead, the data sits in a in RAM, ready to be written in efficient chunks. The file is only flushed (written out to disk) when:

  • The buffer fills up.
  • The program closes the .
  • The operating system shuts the program down (sometimes).

If the program ends without closing the file, the buffered data may never reach the disk, and the file is left incomplete or empty.

Other things CLOSEFILE does

  • Frees the file handle so another program can open the file.
  • Releases system resources (memory, OS structures) used to track the open file.
  • Marks the file as available for reading by other parts of the system.

Common slip: forgetting CLOSEFILE at the end of a file-writing algorithm. Even if a question awards no specific mark for it, the algorithm is incomplete without it.