DoRevision Sign up free

The CSV File Handler

A CSV file stores a whole table of data as plain text. Learn how a program reads it line by line, splits each record at the commas, and writes new data back to the file.

⏱️ 16 min 🎯 14 activities Teachers Not yet rated Students Not yet rated

Revise this, the fun way

Play it interactively, earn XP and build a streak, free.

Start revising free

What you'll cover

Data in a line 📄

How do you store a whole table of data as plain text? You use a **CSV** file, short for **Comma-Separated Values**. Each line is one record, and commas separate the pieces of data.

Words to know 🔑

A few terms describe a CSV file:

Read or write? ⚖️

A program can open a file in different modes.

The delimiter 🎯

In a CSV file, what character separates the fields?

  • A comma
  • A full stop
  • A single space
  • A tab only

Match the term 🔗

  • CSV
  • Record
  • Field
  • Delimiter
  • A text file of comma-separated values
  • One line holding one set of data
  • One piece of data in a record
  • The comma that separates the fields

Reading a file 💡

To read a CSV, a program opens the file, reads a line, and splits that line at the commas to get the separate fields. It repeats for each line, then closes the file. Getting this open, read, split, close order right matters in the exam.

Reading a CSV 🪜

An interactive activity.

Trace the split 📊

An interactive activity.

Complete the idea 🧩

A _____ file stores data as plain text. Each _____ is one line, and a _____ separates the fields. To read the data, a program opens the file, reads a line and _____ it at the commas. To add a new record without deleting the old ones, it opens the file in _____ mode.

CSV record comma splits append image field joins read deletes

About CSV files ✅

Which THREE are true about a CSV file?

  • It is a plain text file
  • Each line is one record
  • Commas separate the fields
  • It is a type of image
  • Fields are separated by full stops

File operations 🔀

  • Open
  • Read a line
  • Write
  • Close
  • Get the file ready to use
  • Fetch the next record as text
  • Save a new line of data
  • Finish and free the file

Which operation? 🧭

An interactive activity.

True or not? 🖍️

An interactive activity.

Explain reading a CSV ✍️

An interactive activity.