java - How to diagnose File.delete() returning false / find unclosed streams? -


I am working with a 3rd party JPEG / EXIF ​​Manipulation Library () which is causing me some headache To do this, I want to change the EXIF ​​data of an image To do this, I have to write the updated version in a temporary file, delete the original and then name the temporary file in the original name.

My problem is that File.delete () calls fail and returns false , probably because the library has opened it in some way But I have done all this in the API which can get it to stop all the currents. Worse: The problem is time-dependent, and unit testing where sometimes it fails and sometimes does not happen - but the code is not multithreaded. Oddly, a library call that removes the problem - but it also removes the EXIF ​​thumbnail, which I do not really want and seeing the code, I can not see at all that any Can stop the stream which can open otherwise.

How does any idea attack this problem?

Edit: This is on Windows XP, Java 6. And the second thing: I have come to know that if I call before System.gc () calling file.delete () , it works - possibly because it Some of the finals are turned on, so it's definitely going to be unpublished.

I will go here for some help with the debugger. A quick excavation through the java.io stuff shows that only one prospect is final () in the candidate FileOutputStream . So slap your breakpoint, run your program, and try System.gc () to release your stream, try FileOutputStream.finalize () Get more. You should answer that this is your problem or not.

Once you can reproduce it, you need to start the FileOutputStream examples with finalizing your code. A good debugger will give you internal JVM object identifiers for each object, so if you can track OID as soon as you can track, and track them when finalized, then you expect that the key call to be Can add to

Finalize with a specific call FileOutputStream .

It may be a long time, however, depending on how complex your application is.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -