i have a clients.dat file with client info in it. i have gone through it to find the record i want to delete, used PushBackBuffer to unread the one i want top delete, skipped that bit and carried on reading the rest and writing it to clients.tmp.

after i have gone through the file and written the undeleted ones to clients.tmp, i want to delete the clients.dat and rename clients.tmp to clients.dat. have got everything right, except the deleting bit. i can't delete the original. i even tried deleteOnExit(), but that only works on the .tmp file.

i initially decided to use a class that handles the connections to the file (like i do with my database applications), but decided that for this i'll need to open the file and read/write, then close my streams again, because files are stupid and not as cool as databases.

i know i'm doing something stupid (because recently i've been making a ton of n00b-like errors and things), so i'm asking you guys for help.

i've attached the code for the FileHandler class which does the writing, deleting and updating of records in the file. if it's something REALLY obvious, then please feel free to hurl abuse at me.

thanks.

nevermind, i figured it out.

solution:

instead of creating the streams to the file in the constructor, i now create the streams in the methods when they're called and as soon as i am done, i close them and the file now deletes without me begging/swearing.

any ideas as to why that makes so much of a difference? the stream objects are still global variables, but now they're just being assigned values in the methods when they're called. to me that makes very little difference, because the closing of the streams still happen in the exact same place.

anyway, feel free to call me a n00b when you answer.

thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.