Input, Output and Files
Files
Files allow a program to communicate with the world outside. Such files are the virtual representation of the devices used. An input file is where the data is read from. This can be data from keyboard, scanner, camera, modem etc. An output file is the file that data will be written to. Once again there are numerous devices.
All data files have the following in common:
- An identifier
- Before use, the file must be opened
- A file may be input, output or both
- The method of file use is specified at opening
- All data types can be read from or written to files
- After use the file must be closed
A file used for input is open for reading. Conversely a file used for output is open for writing. In certain circumstances it is necessary for files to be used for both actions simultaneously.
Files themselves can be a data type and as such should be included in data tables where relevant.
| Type | Identifier | Description |
| Integer | R | Row counter read from file |
| Integer | S | Slot counter read from file |
| Integer | InQuantity | Product quantity read from file |
| File | DataFile | File of warehouse data |
File error
Errors with files can arise:
- The file may not exist. It may not have been created. Attempting to read from a non-existent file is a cause of fatal exception. (Progress is halted.)
- An inappropriate action may occur i.e. attempting to read from a file meant for writing to. (Printers are write to devices and as such they cannot be read from.)
- The devices themselves may not be connected. There may be a fault with the devices or disks.
There must be efforts made to ensure that files are successfully opened. This should be covered at the design stage with appropriate action specified should the file fail to open correctly.
if file opens correctly then do processing else deal with error
Comments, suggestions, ideas to
Stuart Banner
