Queue<String> () { final ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>(); Runtime.getRuntime().addShutdownHook(new Thread("FileUtil deleteOnExit") { @Override public void run() { String name; while ((name = queue.poll()) != null) { delete(new File(name)); } } }); return queue; }