I am having trouble figuring out one implementation problem, I have one class, it behaves like list but instead of holding a file in some collection it saves them on a disk.
The problem occurs when I want to add some element to my list. At the start of my file I have one int that tells me how many objects there are in my list, but I can't figure out elegant way to update this value. I have something like this:
public boolean add(T element)
{
try
{
out.writeObject(element);
out.flush();
//and here we need to update the int in my file
} catch (IOException e)
{
e.printStackTrace();
}
return true;
}
I tried to use something like this:
ObjectOutputStream upd=new ObjectOutputStream(new FileOutputStream(data.getAbsolutePath(),true));
but as I observed it writes some data to the start of the file, some serialization header or sth, how can I update single entry in my file or how to change
ObjectOutputStream
"pointer" to write at the beginning of the file?