I have a program that temporarily saves some Objects to my Hard-Disk only to be re-loaded a few minutes after:
This is the method:
private void save(Object myObject, String path) throws IOException {
final BufferedOutputStream bf = new BufferedOutputStream(
new FileOutputStream(path));
final ObjectOutputStream objOut = new ObjectOutputStream(bf);
objOut.writeUnshared(myObject);
bf.close();
bf.flush();
objOut.flush();
objOut.reset();
}
The problem is that I'm able to delete the file from the disk at runtime, and ending up in a NoSuchFileException later: How to prevent this from happening?
I also tried using
objOut.writeObject(myObject);
instead of
objOut.writeUnshared(myObject);
but still nothing...
Can someone help me? Thanks!
EDIT Read comments for a more detailed description of the request!