RandomAccessFile Quick StartAlbert Guojunyuo@gmail.com1
AgendaRandomAccessFile overviewImplement CRUD functions by RandomAccessFileUse case diagramSequence diagramClass diagramclasses2
What is RandomAccessFile?A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor, or index into the implied array, called the file pointer; input operations read bytes starting at the file pointer and advance the file pointer past the bytes read.Random-access files are solutionInstant accessInsert record without destroying other dataUpdate/delete items without changing other data3
What is RandomAccessFile?imposes no structure on filesProgrammer must create random-access filesSimplest way: fixed-length recordsCalculate position in file from record size and key4
Use Case Diagram5
Class Diagram6
DVD.javaBe made up of a couple of setter and getter methodsDefined length for each column7A DVD record
8
DVDClient.javaPlay the role of client to do CRUDC (Create): addDVD()R (Read): findAll() and findByCriteria()U (Update): modifyDVD()D (Delete): deleteDVD9
DvdFileAccess.javaAll random access file-related codes are in this class10
findAll()11
12Retrieve DVD data based on the cursor
13
14
findByCriteria()15
findByCriteria() – cont.16
persistDvd()17
18
19
modifyDVD()20
21
22
deleteDVD()23
24

RandomAccessFile Quick Start