15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8: Reading<br />

and Saving Files<br />

In This Chapter<br />

Storing data in text files and database files<br />

Storing your fixed size data in random-access files<br />

Storing your varying size data in untyped files<br />

Almost every program needs to save data. Spreadsheets need to save<br />

numbers and <strong>for</strong>mulas, word processors need to store text, databases<br />

need to store names and addresses, and even video games need to store the<br />

top ten highest scores.<br />

To save data, programs store in<strong>for</strong>mation in a file. After a program stores<br />

data in a file, it eventually needs to open that file and retrieve that data<br />

again. To save data in files, programs generally use one of four methods:<br />

✦ Text files<br />

✦ Random-access files<br />

✦ Untyped files<br />

✦ Database files<br />

Storing Data in Text Files<br />

A text file, sometimes called an ASCII or plain text file, contains nothing but<br />

characters, such as letters, numbers, and symbols.<br />

Text files only store actual data, such as names and addresses, but don’t<br />

contain any <strong>for</strong>matting in<strong>for</strong>mation, such as fonts or underlining. Because<br />

text files only contain data, they represent a universal file <strong>for</strong>mat that any<br />

computer, from an ancient Commodore-64 to a Cray super computer, can<br />

read and use.<br />

Text files typically store data as one long string of data like this:<br />

Joe Smith 123 Main Street New York NY 10012

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!