On 2018-02-18, Al Le wrote: > 1. Is there an Ant API to create a temp file? Or should I just use the > standard Java API for this?
There is FileUtils.createTempFile which of course uses the standard Java API under the covers, but allows you to specify whether the file should actually be created and whether it should be deleted on VM exit in a single method invocation. > 2. How would I ensure that the file is deleted after the task > completes? Is there some mechanisms for this is Ant? Or should I just > carefully program try-catch-finally and delete the file in the finally > block (or use try with resources)? Use deleteOnExit as a safety net in addition to a finally block. If you plan to see your task running on Windows, be extra careful to check the return value of File.delete - or better, yet, use FileUtils.tryHardToDelete and check the return value. Sometimes the JVM simply doesn't seem to be able to remove files it has created soonish after all streams have been closed on Windows. Stefan --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@ant.apache.org For additional commands, e-mail: user-h...@ant.apache.org