Previous topic | Ada Home Page | Index

Direct access files

Direct access files are structured binary files, in which is it possible to go directly to a desired record.

To enable this, a file index is used.

When it can be manipulated:

The DIRECT_IO package is used

An example program shows the use of a direct access file in a program dealing with bank accounts. A direct access file is appropriate here because only one of the many records in the file is updated.


Using direct access files

General file management

I/O library instantiation

variable definition

open/close files

procedures and functions that use the file index:

Input/Output

relative to index:

        SET_INDEX (accfile, recordnum);
        WRITE (accfile, rec);

specific location:

        WRITE (accfile, rec, recordnum);

file index is automatically incremented after I/O

        while INDEX(accfile) <= 100 loop
            READ (accfile, rec);
        end loop;


Previous topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 23 Feb 96