RandomAccess

RandomAccess - 4 For writing a new record you must add it...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 The key to random access files is proper positioning of the file pointer prior to a read or write. Steps: 1. Open the file RandomAccessFile myFile = new RandomAccessFile(fileName, "rw") 2. Position the file pointer: myFile.seek(num * RECORDSIZE) 3. Read or write the record, using the proper method type: myFile.writeUTF(firstName) or firstName = myFile.readUTF()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 4. For writing a new record, you must add it to the end of the file (unless you are using some kind of hashing algorithm to dete r m bytes = myFile.length() to determine how many bytes are already in the file. All you need to do then is use RECORDSIZE to figure out how many reco Sheet1 Page 2 // For string data write // For string data read...
View Full Document

This note was uploaded on 04/18/2008 for the course CIT 295 taught by Professor Purdum during the Fall '08 term at Purdue.

Page1 / 2

RandomAccess - 4 For writing a new record you must add it...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online