aimnova.
DashboardMy LearningPaper MasteryStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aimnova.

AI-powered study platform for smarter revision, past-paper analysis and examiner-style feedback.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.8afc4e3

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer ScienceTopic 6.5File processing
Back to Computer Science Topics
6.5.15 min read

File processing

IB Computer Science • Unit 6

Exam preparation

Practice the questions examiners actually ask

Our question bank mirrors real IB exam papers. Practice under timed conditions and track your progress across topics.

Start Practicing

Contents

  • Data that outlives the program
  • The three modes
  • Reading, and getting it wrong
  • Exam-style question
The big idea: Variables disappear when the program ends. A file does not.

Working with one always follows the same three steps: open, use, close.
The mode is chosen when you open it: r read · w write · a append.

And w empties the file immediately, before you write anything. Choosing w when you meant a destroys everything that was there.

Free preview

This is the free notes preview

You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:

  • FlashcardsLock in vocabulary and key terms with spaced repetition.
  • Practice questionsAnswer exam-style questions and get instant AI marking.
  • Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
  • Personalised study planA daily plan built around your exam date and weak areas.
Start Studying Free Full access to Aimnova Pro · cancel anytime

r — read

  • Reads what is there; cannot write
  • Fails if the file does not exist
  • The safe default: it cannot damage anything

w — write

  • Empties the file at once, then writes
  • Creates it if it does not exist
  • Right only when replacing the contents entirely
  • The destructive one — be certain before using it

a — append

  • Adds at the end, keeping what was there
  • Creates it if it does not exist
  • Right for logs, records and anything accumulating
with closes it for you: Opening a file inside a with block closes it automatically when the block ends — even if something goes wrong inside.

That is the finally block from exception handling, built into the language.

Feeling unprepared for exams?

Get a clear study plan, practice with real questions, and know exactly where you stand before exam day. No more guessing.

Get Exam Ready FreeYour first topic is free to keep • No credit card required
1

Every line ends with a newline

2

Everything read is text

3

Write a newline yourself

4

Close it, always

How this is tested — you must choose the right mode and handle the file actually failing. It comes up two ways:

Paper 2 — working with code

  • Construct code to read, write or append, 4-6 marks
  • Explain the difference between the modes
  • Say why a file must be closed

Paper 2 — the algorithmic-thinking question

  • Reason about file handling with no code shown
  • Explain what would go wrong with the wrong mode
The classic trap: Opening in w when you meant a. The file is emptied the moment it opens, before a single line is written — and the previous contents are gone with no warning.
IB-style questionConstruct[6 marks]

A program must add today's attendance to a running log, then report how many days are recorded. Write it, handling the file being missing.

Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on File processing. Write your answer and get instant AI feedback — just like a real IB examiner.

the three basic operations performed on a file. [1 mark]

Related Computer Science Topics

Continue learning with these related topics from the same unit:

6.1.1Variables and data types
6.1.2Substrings
6.1.3Exception handling
6.1.4Debugging
View all Computer Science topics

Improve your exam technique

Command terms, paper structure, and mark-scheme tips for Computer Science

Previous
6.4.3Bubble and selection sort
Next
Fundamentals of OOP7.1.1

23 questions to test your understanding

Reading is just the start. Students who tested themselves scored 82% on average — try IB-style questions with AI feedback.

Start FreeView All Computer Science Topics