Dear Readers,
I am developing an application that stores "messages" in array list
and writes new entries to a disk file at the end. This file is used
incase the user choses to restart the program. When the program is
restarted the messages are replayed so the application knows where it
is up to.
I am not allowed to use a **database** I have been instructed to use a
flat file. The application I am replacing does that.
Everything works fine until someone wants to delete a message from the
list. In the Arraylist I simply remove the entry. Which is easy.
However for the file I re-create (delete and re-create) the entire
file with the new records - which seems a waste and exposes possible
danger if the users shuts the application down while re- creating the
file. I know this is small, but I would like to remove all risks.
I am writing the file as binary file stream, with a "message" length
followed by the variable length messages.
Is there any way I can deleted records in the centre of the file
without recreating the file?
Failing deleting the records is there a way I could rewrite a record
in the current file to indicate it should not be reloaded on restart.
I have plenty of space free in the records for some flag.
I know that a database is a better way to do this however I have been
told not to use a database.
Any suggestions.
Stuart