Forcibly closing files?

I am currenting making batch utility to test different combinations of java optimisers for my J4k entry this year.

The utilitiy calls the main(…) methods of other the optmising utilities. Each of these utilties produces a file as output.

It seems that some of these utilities do not release their handle to the file so i cannot delete these files at the end of the batch run.

How can I either forcibly delete the file even if there are still handles to it or “de-initalize” static references to the files internally to these utilities?

I do not have access to the source code of the utilities.

Or is there an other way to remove these files?

I think if i created a new runtime for each utilitiy i should beable to delete the files, however this would dramatically increase processing time.

My batch utility is working well thus far and has been able to compress the Jar used for Markus_Persson’s entry l4krits (http://www.java-gaming.org/forums/index.php?topic=15453.0) from 4,027 bytes to 3,783 bytes

I plan to release the utiltiy once it is in a more usable state.

If you’re providing the original file handle, you could create it as a temporary file, and ask java to automatically delete it when the JVM exits. Have a rummage around in File.*

But I suspect you’re not :frowning:

I have been fiddling around with File.deleteOnExit()

It seems to work with most of the files appart from a directory and the file inside this directory… I am still trying different options.

It is not the idea solution but it does show the most promise.

Cheers

It seems that the deleteOnClose did not have an effect after all :frowning:

I have isolated the utilites which hold on to a file reference. I am now calling these utilies in thier own VM. The performance hit is within acceptable parameters so I think i will keep this solution.

Thanks for your help!

This sounds interesting, but what happens if the JVM crashes or is forcibly ended by the user? Does it still delete the file?