Copying a line of text from one file to another
Writes the line held in LineOfText (read earlier from FileA.txt) into FileB.txt, copying it between files. Both files must be opened first and each one closed after.
Understanding Copying a line of text from one file to another in IGCSE Computer Science Paper 2
What it does: WRITEFILE puts the contents of LineOfText, read earlier from FileA.txt, into FileB.txt. Every opened file needs its own CLOSEFILE statement, so two files mean two CLOSEFILE lines. The source file is read from, so it is opened FOR READ. Opening it FOR WRITE would replace its data. One variable holds the line between the READFILE and the WRITEFILE, so the line can be copied.
Common mistakes: FileA.txt is the source file, so it must be opened FOR READ. Opening it FOR WRITE would wipe its contents and stop READFILE from working. It should be OPENFILE FileA.txt FOR READ. The line must be written to the destination file, FileB.txt. FileA.txt is open for READ, so it cannot be written to. It should be WRITEFILE FileB.txt, TextLine.
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 500–522) and word search (Modules 500–538) and definitions worksheet (Modules 500–522) and word scramble (Modules 500–522).
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
▶ Run these on the board — two answers, the class points left or right, you reveal why. No devices.
Match the Pairs
Key Term
WRITEFILE FileB.txt, LineOfTextFill in the Blanks
Spot the Error
Student with a class code? Join your class →
Classroom tools: Hangman · Bingo · Heads or Tails · Higher or Lower · Name Picker · Team Generator · Seating Plan