I need to execute a method, (a method which creates a file), when I exit my program, how would I do this?
Add shutdown hook. See this javadoc.
Example:
public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { System.out.println("In shutdown hook"); } }, "Shutdown-thread")); }
1.4m articles
1.4m replys
5 comments
57.0k users