randomaccessfile quick start

24
+ RandomAccessFile Quick Start Albert Guo [email protected] 1

Upload: guo-albert

Post on 22-May-2015

697 views

Category:

Business


0 download

TRANSCRIPT

Page 1: RandomAccessFile Quick Start

+

RandomAccessFile Quick StartAlbert [email protected]

1

Page 2: RandomAccessFile Quick Start

2+Agenda

RandomAccessFile overview

Implement CRUD functions by RandomAccessFile Use case diagram Sequence diagram Class diagram classes

Page 3: RandomAccessFile Quick Start

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

Page 4: RandomAccessFile Quick Start

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

Page 5: RandomAccessFile Quick Start

5+Use Case Diagram

Page 6: RandomAccessFile Quick Start

6+Class Diagram

Page 7: RandomAccessFile Quick Start

7+DVD.java

Be made up of a couple of setter and getter methods

Defined length for each column

A DVD record

Page 8: RandomAccessFile Quick Start

8+

Page 9: RandomAccessFile Quick Start

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

Page 10: RandomAccessFile Quick Start

10+DvdFileAccess.java

All random access file-related codes are in this class

Page 11: RandomAccessFile Quick Start

11+findAll()

Page 12: RandomAccessFile Quick Start

+ 12

Retrieve DVD data based on the cursor

Page 13: RandomAccessFile Quick Start

+ 13

Page 14: RandomAccessFile Quick Start

+ 14

Page 15: RandomAccessFile Quick Start

+ 15

findByCriteria()

Page 16: RandomAccessFile Quick Start

+ 16

findByCriteria() – cont.

Page 17: RandomAccessFile Quick Start

+ 17

persistDvd()

Page 18: RandomAccessFile Quick Start

+ 18

Page 19: RandomAccessFile Quick Start

+ 19

Page 20: RandomAccessFile Quick Start

+ 20

modifyDVD()

Page 21: RandomAccessFile Quick Start

+ 21

Page 22: RandomAccessFile Quick Start

+ 22

Page 23: RandomAccessFile Quick Start

+ 23

deleteDVD()

Page 24: RandomAccessFile Quick Start

+ 24