Direct File Organization
Keep in mind that files are simply a series of bytes. Say you could keep track of the number of records written in a file, then you could pin-point a certain record at position n by adding an offset to the starting position of the file:

Offset = number of records * record length
Note that the first record is record zero.
  • Example: say we have a record size of 32 bytes. The 10th record would start at an offset position calculated as follows and have a length of 32 bytes:

32 * 10 = 320th byte position.Therefore, to access to the record in a certain position, one has to provide the offset position of this record. (This differs between different operating systems and programming languages).
  • Once the file name and position of the record in the file is provided to the operating system, the operating system can place the read head over the according track and sector of the HDD.
    • The operating system knows where which file is located by using a file management system to keep track of the start of files on the HDD.
  • The actual reading of the data from the HDD is just as in any other form of access. The data is then stored in variables (which need to be the of the same type) defined in the program reading the data.
How does the user remember the position of data in a file?
  • Key hashing
    • User enters the key desired (ex. surname) and the computer converts this key into a record number to allow for direct access
  • Identification numbers (ID)
    • This also help to keep track of how many records already exist (as each ID is unique)
    • Example of generating an ID (taken from "Computer Science Java Enabled"):
Next Available Record Location = 100
Year = 2000
Check digit = 2000 mod 100 = 0
      • This would give an ID of 20001000, for example.
    • To read the record, the ID would be entered and the correct record can be found and read.

Example of a basic file direct access algorithm (taken from "Computer Science Java Enabled"):
(assuming record 1 has the number 0)

set lengthOfRecord = length of record in bytes
open file
get recordNumber
moveto byte position recordNumber*lengthOfRecord
read record
edit record
write record
close file

Last edited: Jocbe
Last update: 26. September 201

  • Jones, Richard. Computer Science Java Enabled. Victoria: IBID Press, 2004.