The Cambridge IGCSE 0478 syllabus states that file storage is used “to preserve information beyond the life of a single program execution”. The four purposes required for the exam are:
.csv file that a spreadsheet can import..txt and .csv.| Aspect | Advantages | Disadvantages |
|---|---|---|
| Persistence | Data survives program termination; can be accessed later. | Requires explicit read/write code; loss if not saved correctly. |
| Sharing | Multiple programmes/users can work with the same information. | File‑format incompatibilities may arise. |
| Backup & Security | Files can be protected with permissions or simple encryption. | Improper handling may expose sensitive data. |
| Performance | Large data sets can be processed without exhausting RAM. | File I/O is slower than accessing data in memory. |
| Programming complexity | Simple I/O commands (OPEN, READ, WRITE, CLOSE) are easy to learn. | Program must handle errors (file not found, permission denied) and check end‑of‑file. |
Exam questions often ask you to choose the correct mode, e.g. “append the new score to scores.txt”.
In pseudocode you normally test the result of OPEN FILE. If it fails, display an error message and stop the programme.
READ item – reads a single data item (e.g. a number or a word) separated by a space or comma.READ LINE – reads an entire line of text, preserving commas, spaces, etc.WRITE item – writes a single item (no line break unless you add one).WRITE LINE – writes a complete line and automatically moves to the next line.When reading a file you must stop when the end of the file is reached. The usual exam pattern is:
OPEN FILE "scores.txt" FOR READ
IF NOT FILE OPENED THEN
DISPLAY "File not found"
STOP
END IF
WHILE NOT EOF
READ LINE line
DISPLAY line
END WHILE
CLOSE FILE
The condition WHILE NOT EOF guarantees that the loop terminates exactly at the end of the file.
OPEN FILE "scores.txt" FOR WRITE
IF NOT FILE OPENED THEN
DISPLAY "Unable to create scores.txt"
STOP
END IF
WRITE LINE "Alice,85"
WRITE LINE "Bob,92"
WRITE LINE "Charlie,78"
CLOSE FILE
OPEN FILE "scores.txt" FOR APPEND
IF NOT FILE OPENED THEN
DISPLAY "Unable to open scores.txt for appending"
STOP
END IF
WRITE LINE "Diana,88"
CLOSE FILE
"data/scores.txt" (relative to the programme’s folder)."C:\Users\Student\Documents\scores.txt" (full location on the computer).Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.