• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checking EOF with raf.readShort()

 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am using RandomAccessFile(raf).

raf.readBytes(byte b[]) return -1 if end of file is encountered, but I am also using raf.readShort as shown above. readShort() does not return -1 but throws EOFException.

To check for the eof in my code, is catching EOFException the only way? I could use read() or read(byte[]) which return -1 for EOF and then convert the 2 bytes to short, but that is the long way. Is there a better way to do this?
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vishwa,

Another way of doing is computing the last record position in the file (file size - record length).

Regards,

Phil.
 
reply
    Bookmark Topic Watch Topic
  • New Topic