Access methods describe how the system retrieves or modifies data within a file. There are three primary file access methods:
1. Sequential Access
Data in the file is accessed in a linear order, from beginning to end.
Characteristics:
-
Most common method.
-
Used in text files, log files, and batch processing.
-
Cannot skip ahead without reading through intermediate data.
Example:
To read the 5th record, the system reads records 1 through 4 first.
Advantages:
Disadvantages:
-
Slow for random access—you must read data in sequence.
-
Not suitable for applications that need quick lookup (e.g., databases).
2. Direct Access (Random Access)
What is it?
Data can be accessed directly using an index or position, like jumping straight to a specific byte or block.
Characteristics:
Example:
To read the 10th record, you go directly to its location (e.g., record[9]).
Advantages:
Disadvantages:
3. Indexed Access
Uses an index (like a table of contents) to locate blocks or records in the file.
Characteristics:
-
Combines benefits of sequential and direct access.
-
Index contains pointers to file locations.
-
Useful when accessing large files or records by a key (e.g., ID).
Example:
An index might map:
Key = 102 → Block 9,
Key = 110 → Block 3
Advantages:
Disadvantages:
Conclusion
Understanding file access methods helps optimize performance and storage use. Choosing the right method depends on:
-
How the data is used (read often? updated frequently?).
-
The size and structure of the file.
-
Application requirements (e.g., logs vs databases).