Java Reference
In-Depth Information
readPartFromFile(f).printPart();
System.out.printf("\n");
} //end for
} //end printFileInOrder
Suppose this function is added to Program P7.9 and called with the following statement after the index has
been retrieved:
printFileInOrder(index, fp);
The following will be printed:
File sorted by part number:
Part number: BLJ375
Part name: Ball-Joint
Amount in stock: 12
Price: $11.95
Part number: DKP080
Part name: Disc-Pads
Amount in stock: 16
Price: $9.99
Part number: FLT015
Part name: Oil-Filter
Amount in stock: 23
Price: $7.95
Part number: GSF555
Part name: Gas-Filter
Amount in stock: 9
Price: $4.50
Part number: PKL070
Part name: Park-Lens
Amount in stock: 8
Price: $6.50
7.9 Updating a Random Access File
The information in a file is not usually static. It must be updated from time to time. For our parts file, we may want to
update it to reflect the new quantity in stock as items are sold or to reflect a change in price. We may decide to stock
new parts, so we must add records to the file, and we may discontinue selling certain items, so their records must be
deleted from the file.
Adding new records is done in a similar manner to loading the file in the first place. We can delete a record
logically by marking it as deleted in the index or by simply removing it from the index. Later, when the file is
 
Search WWH ::




Custom Search