Hai I have developed a standalone application in which when an user logs in, an log file will be created and when the application is closed the log file gets deleted.But when i shutdown the system with out closing the application the log file is not geting deleted.what can i do to delete my log file during shutdown or system crash that is when power supply is switched off when my application is running.Can someone help me to delete the log file during shutdown
Thanking you Chaithu
If the VM is not properly shutdown it may not start the registered shutdown hooks. So in addition to File.deleteOnExit() (which I assume you are using, you’re not giving enough details) you should maybe also think about simply deleting all files you created in earlier invocations of your application when your application starts up.
You can schedule a file for deletion when the JVM exits with the deleteOnExit() of the File class. However in a hard shutdown like a system crash, there is nothing you can do to ensure the log file is deleted cleanly. Your best option in this case would be to cleanup the next time the application starts if it's really that much of a problem.
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