Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Andrew's Read DB Method

 
Shan Jun Hao
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to do what Andrew has demostrated in his book.



I keep on getting errors with the short value - java.lang.NumberFormatException: For input string: "". Can anyone tell me how to convert the String to a short value?
 
Petr Hejl
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You read two bytes, that I believe creates String with characters below ' ' (0x32). So it is trimmed to "" (as described in api for trim).
 
Daniel Bryant
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shan,

I personally read the two bytes indicating a deleted flag before reading the rest of the record from the file - that way you can read the two bytes directly into a byte array (bypassing the need for conversion) and check if the record is deleted or not.

The added bonus of this approach is that if you determine a record is deleted you do not need to read the rest of the record, and accordingly save valuable time synchronizing and reading the DB file.

Best wishes,

Daniel
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!