TEXT FILES
Purpose of storing data in a file
•Computer programs store data that will be required again in a file.
•While any data stored in RAM will be lost when the computer is
switched off, when data is saved to a file it is stored permanently.
•Data stored in a file can thus be accessed by the same program at
a later date or accessed by another program.
•Data stored in a file can also be sent to be used on other
computer(s).
•The storage of data in files is one of the most used features of
programming.
Benefits of textfiles
• Data from the arrays is written to the files before
the program is terminated or computer is
switched off
• Data can then be read from the files and written
the arrays
• No need to (re-)enter the data manually - you
only need to enter data once
• Text files contain a sequence of characters.
•Text files can include an end of line character that
enables the file to be read from and written to as
lines of characters.
•In pseudocode, text files are handled using the
following statements.
•To open a file before reading from it or writing to it:
Reading Data from a text file