file1
 
electronic information is mostly stored in files that are kept in disk storage.
 
a file is a semi-permanent, named collection of data. a file is usually stored on magnetic media, such as a hard disk or magnetic tape. semi-permanent means that data saved in files stays safe until it is deletingd or modified. named means that a particular collection of data on a disk has a name, like mydata.dat and access to the collection is done by using its name.a typical desktop computer has one hard disk that can store up to 100 billion bytes of data. this is roughly the equivalent of 100 billion characters. data on a disk is always organized into files, much as data in a library is organized into books.
 
input and output
 
data saved in variables vanishes when the program stops. but data saved in a file remains there when the program stops. so your occasional credit card charges eventually get saved in a disk file, where they remain for months (unfortunately). data flowing into a program are called input. when a file is used as a source of data for a program it is called an input file. a program is said to read data from an input file. data flowing out of a program are called output. when a file is used as the destination of data for a program it is called an output file. a program is said to write data to an output file.the same file can be used as an output file for one program, and later as an input file for another (or the same) program. for example, when you use a word processor you typically read data from a file (often called a document), then later save the data to the same file. sometimes the same file can be used simultaneously as an input file and as an output file. (these notes do not cover how to do that.)
 
types of files
 
there are two main ways a file can be organized:
 
1.          sequential access — the data are placed in the file in a sequence like beads on a string. data are processed in sequence, one after another. to reach a particular item of data, all the data that proceeds it first must be read.
 
2.          random access — the data are placed into the file by going directly to the location in the file assigned to each data item. data are processed in any order. a particular item of data can be reached by going directly to it, without looking at any other data.