Java Reference
In-Depth Information
fd.sync();
// Perform non-critical write operation where synchroniza-
tion is not necessary.
raf.write(...);
// Do other work.
// Close file, emptying output buffers to disk.
raf.close();
RandomAccessFile
isusefulforcreatinga
flat file database
,asinglefileorgan-
ized into records and fields. A
record
stores a single entry (e.g., a part in a parts data-
base) and a
field
stores a single attribute of the entry (e.g., a part number).
Aflatfiledatabasetypicallyorganizesitscontentintoasequenceoffixed-lengthre-
cords.Eachrecordisfurtherorganizedintooneormorefixed-lengthfields.
Figure8-1
illustrates this concept in the context of a parts database.
Figure 8-1.
This flat file database describes automotive parts.
Accordingto
Figure8-1
,eachfieldhasaname(partnum,desc,qty,anducost).Also,
eachrecordisassignedanumberstartingat0.Thisexampleconsistsoffiverecords,of
which only three are shown for brevity.
Note
The term
field
is also used to refer to a variable declared within a class. To
avoid confusion with this overloaded terminology, think of a field variable as being
analogous to a record's field attribute.
To show you how to implement a flat file database in terms of
RandomAc-