Download - RandomAccessFile Quick Start
2+Agenda
RandomAccessFile overview
Implement CRUD functions by RandomAccessFile Use case diagram Sequence diagram Class diagram classes
3+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 solution Instant access Insert record without destroying other data Update/delete items without changing other data
4+What is RandomAccessFile?
imposes no structure on files Programmer must create random-access files Simplest way: fixed-length records
Calculate position in file from record size and key
5+Use Case Diagram
6+Class Diagram
7+DVD.java
Be made up of a couple of setter and getter methods
Defined length for each column
A DVD record
8+
9+DVDClient.java
Play the role of client to do CRUD C (Create): addDVD() R (Read): findAll() and findByCriteria() U (Update): modifyDVD() D (Delete): deleteDVD
10+DvdFileAccess.java
All random access file-related codes are in this class
11+findAll()
+ 12
Retrieve DVD data based on the cursor
+ 13
+ 14
+ 15
findByCriteria()
+ 16
findByCriteria() – cont.
+ 17
persistDvd()
+ 18
+ 19
+ 20
modifyDVD()
+ 21
+ 22
+ 23
deleteDVD()
+ 24