The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP, SCJD
Originally posted by Jethro Borsje:
I am not using a RAF, but a DataInputStream to read the records from my data file. I catch the EOF exception and use this to stop reading, because the end of file is reached. I am not sure if this is correct usage of the EOF exception...
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Originally posted by Andrew Monkhouse:
The thing about exceptions is that they are supposed to be exceptional (unexpected) situations. In addition, when they do occur, the creation of the Exception object is a heavyweight process (generally not desirable).
In this particular case, you know how long records are, you know how long the file is, and you know how large the meta-data is. Therefore you should know how many records you have (as Satishkumar demonstrates). Given that, you should be able to construct code that only ever reads data that is really there, and an EOFException will truly be an unexpected situation, deserving to be processed outside of normal application flow.
Originally posted by Andrew Monkhouse:
As an aside, you mention that you are using DataInputStream to read the data - what about writing records back out? If you only need to update record number 5, how do you go about doing that?
SCJP, SCJD
Trust God, but always tether your camel... to this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|