I want to run a .bat
file when I close my Java application.
I try, but when I close Java app the bat file doesn't start.
You might want to look into shutdown hooks. Basically you can register an unstarted thread, it will be started by the JVM when the exit process is started.
Runtime.getRuntime().addShutdownHook(thread)
According to the doc:
The Java virtual machine shuts down in response to two kinds of events:
I can think of two options.
Only 1 will work if your process is killed. How are you trying to do it at the moment, and how is it failing? Without this information we can't help you.
Please go through this http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html . Use Runtime.getRuntime().addShutdownHook(thread) to associate it.
如果您的应用程序是扩展SingleFrameApplication
的桌面应用程序,则可以覆盖其退出方法: public void exit(EventObject event)
并添加代码以在此处启动文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.