I'm working with a 3rd party JPEG/EXIF manipulation library (Mediautil) that is causing me some headaches. I want to change an image's EXIF data. To do this, I need to write the updated version to a temporary file, delete the original and then rename the temp file to the original name.
My problem is that the File.delete() call fails and returns false, presumably because the library still has it opened in some way - but I have done everything I can find in the API to make it close all streams. Even worse: the problem seems to be timing-dependant, and the Unit tests where it occurs sometimes fail and sometimes not - but the code is not multithreaded.
Bizarrely, there is one library call that removes the problem - but it also removes the EXIF thumbnail, which I don't actually want. And looking at the code, I absolutely can't see where it closes any streams that might otherwise stay open.
Any ideas how to attack this problem?
Edit:
This is on Windows XP, Java 6. And another thing: I have found out that if I call System.gc() before calling File.delete(), it works - presumably because that triggers some finalizer. So it definitely seems to be an unclosed stream.