FILES

FILE INPUT/OUTPUT

• For program to retain data between the times it is run, you must save the data
    • Data is saved to a file, typically on computer disk
    • Saved data can be retrieved and used at a later time
• "Writing data to" : saving data on a file
• Output file: a file that data is written to
• "Reading data from" : process of retrieving data from a file
• Input file: a file from which data is read

TYPE OF FILES

In general, two types of files
    1. Text file: contains data that has been encoded as text
    2. Binary file: contains data that has not been converted to text Two ways to access data stored in file

Two ways to access data stored in file
    1. Sequential access: file read sequentially from beginning to end, can't skip ahead
    2. Direct access: can jump directly to any piece of data in the file

    There are always three steps that must be taken when a file is used by a program.
• Open the file - Opening a file creates a connection between the file and the program. Opening an output file usually creates the file on the disk and allows the program to write data to it. Opening an input file allows the program to read data from the file.
• Process the file - In this step data is either written to the file (if it is an output file) or read from the file (if it is an input file).
• Close the file - When the program is finished using the file, the file must be closed. Closing a file disconnects the file from the program.

Open File

File Mode