WRITE mode creates a new file and replaces old data
Opens a file for writing. A new file is created if none exists. If it does exist, all its old data is erased and replaced, so check before overwriting data you need.
Understanding WRITE mode creates a new file and replaces old data in IGCSE Computer Science Paper 2
What it does: WRITE mode creates the file when it is not already there, so the program can start saving data straight away. Opening Results.txt FOR WRITE would erase last week's results. A new file name leaves the old file untouched. Opens a file for writing. A new file is created if none exists. If it does exist, all its old data is erased and replaced, so check before overwriting data you need.
Common mistakes: The file name is a string, so it must be in quotes: WRITEFILE "Data.txt", "Liam". Without quotes it looks like a variable, not the file that was opened for WRITE. READ mode only reads an existing file. It does not create a new file or replace old data. To save the score the file must be opened FOR WRITE.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 479–488) and word search (Modules 479–499).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
OPENFILE "Scores.txt" FOR WRITEFill in the Blanks
Spot the Error
Student with a class code? Join your class →