First thing you must know is the amount of storage used by each of those primitive types. For example, a boolean needs 1 byte. Then you can use some squared paper and mark off, in order, boxes for each of those primitives that are written to the file. The length of each box should represent the number of bytes needed for the datatype it contains. Write in each box the data it contains. For example, the first box contains true, the second box contains the value 123456. Then you must seek byte 5 (starting from the beginning, counting from 0). You must then read the number contained in the next x bytes where x is the length of a primitive int. If you don't get 7980, I haven't explained it well enough [ March 25, 2003: Message edited by: Barry Gaunt ]
Thanks Barry. I've got it. seek(0) will position before byte of boolean (true) seek(1) will position before byte of integer (123456) an integer is 4 bytes seek(5) will position before byte of second integer (7890)
Joined: Aug 03, 2002
You got what it takes!!!
subject: Question about RandomAccessFile (1.2 exam)