Hi there, This is my first message to this list.
I am a translator who writes scripts in groovy every now and then to automate some tasks, although I'm not really a programmer. I have written a script that downloads some plugins (jar files) and the script runs within the Java environment that uses those plugins. The script must download the latest version of the plugin, overwrite it if it already exists locally and delete any other (earlier) versions of the same plugin. For example, the script downloads remote file plugin-omt-package-1.6.3.jar from a certain URL, and must delete, say, existing local file plugin-omt-package-1.6.2.jar. The problem: However, existing local files are locked by my Java application (within which the groovy script runs) so the script doesn't delete them. Apparently there is a bug on Windows (not on Linux) which is why a Java application cannot easily release the lock. Somebody explains the bug in this thread https://stackoverflow.com/questions/4179145/release-java-file-lock-in-windows/48489019#48489019 I have followed the suggestion in that page and tried to use ByteArrayOutputStream in my delete_other_versions function: ByteArrayOutputStream bos = new ByteArrayOutputStream(0); FileOutputStream fos = new FileOutputStream( new File(path_to_file) ); bos.writeTo(fos); fos.close(); System.gc() file.delete() // me beating about the bush My full code is here: https://gist.github.com/msoutopico/7b2b340e9cec830f4b2ce207575e7525 That seems to delete the content of the files (I can see they have now a size of 0 kb), but not the files themselves. I would be grateful for further suggestions for workarounds about ways I could manage to delete them. Thanks in advance. Cheers, Manuel