Chapter 8

Reading and Saving Files

IN THIS CHAPTER

Bullet Storing data in text files

Bullet Storing fixed-size data in random-access files

Bullet Using untyped files to store data of varying sizes

Bullet Working with database files

Almost every program needs to save data. Spreadsheets need to save numbers and formulas, word processors need to store text, databases need to store names and addresses, and even video games need to store the top ten highest scores.

To save data, programs store information in a file. After a program stores data in a file, it eventually needs to open that file and retrieve that data again. To save data in files, programs generally use one of four methods:

  • Text files
  • Random-access files
  • Untyped files
  • Database files

Storing Data in Text Files

A text file, sometimes called a plaintext file, contains nothing but characters, such as letters, numbers, and symbols.

Text files only store actual data, such as names and addresses, but they don’t contain any formatting information, such as fonts or underlining. Because text files contain only data, they represent a universal file format ...

Get Beginning Programming All-in-One For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.