I have some application, which has ability to update itself. Its downloads the jar file from the net, and then tries to replace used jar to run this application by downloaded one. But I cannot to do that, because the file is locked by windows, because application is still running.
Does anybody know some workaround of that?
Open the Start menu, then the File Explorer and find the formerly locked file. Remove the file. Click the previously locked file, then the “Home” tab, and “Delete” in the toolbar. Or, you may select the file by clicking on it and then pressing the “Delete” key.
Delete a file with Java IO 2.1 For the legacy File IO java.io. * , we can use the File. delete() to delete a file, and it will return boolean, true if file deletion success, false otherwise.
To force delete file using Java, we can use the FileUtils or FileDeleteStrategy class available in Apache Commons Io. We can also use FileDeleteStrategy class of apache commons io to force delete file, even if the file represents a non-enpty directory . the delete() method deletes the file object.
One of the popular solutions for this is to run your updater as a separate program. Have you ever noticed that Firefox has to restart when it is updated? Well that is because a separate process (updater.exe) is updating the files, then starting Firefox again.
You can try this approach. The only obstacle I see in the way is trying to automate the MAIN program to close itself. The only portable way to do this (in my head) is for the main application to wait for a kill signal via a local socket, and the updater can send the command through local networking. One more thing you have to consider is that the updater has to run in a separate java process. If your main program just creates a new Updater object, the Updater will co-exist with the main program's JVM, which brings you back to square one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With