Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataInputStream vs DataOutputStream

 
Eric Ushie
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my assignment, i am asked to use the format of DataInputStream and DataOutputStream. for reading, i can easily combine the readXxx() and
skip(long) methods to read values and reposition the file pointer respectively.

However, when it comes to writing, DataOutputStream has writeXxx() but these methods can only write to the end of the file. there is no method to reposition the file pointer in order to write to a desired position.

My question is, is there a way to reposition the file pointer for writing using DataOutputStream class?

I have 2 alternative approaches and i'll like some critique on my idea:

(1) I have thought of reading the entire database to memory and overwrite the database during an update/delete action, i however have the doubt that
i could be marked down for not considering that the database could grow so large someday that its entirety cannot be held in the memory - a reliability/maintenance flaw.

(2) I have also considered a temporary file to hold my database content during an update/delete. But i'm thinking of the performance downside of this approach, even though performance was not emphasized in my assignment, i dont want to take things for granted.

thanks for your expected response.
 
Eric Ushie
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Dudes, i just discovered that RandomAccessFile (RAF) extends both DataInput and DataOutput, so i can leverage on the writeXxx() methods to write to the file and the seek(long) method for file pointer repositioning.

Thanks everyone
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic