Tempfile Task

Description

This task sets a property to the name of a temporary file. Unlike java.io.File.createTempFile, this task does not actually create the temporary file, but it does guarantee that the file did not exist when the task was executed.

Parameters

Attribute Description Type Required
property Sets the property you wish to assign the temporary file to. String Yes
destdir Sets the destination directory. File No; defaults to basedir
prefix Sets the optional prefix string for the temp file. String No
suffix Sets the optional suffix string for the temp file. String No
deleteonexit Whether the temp file will be marked for deletion on normal exit of JVM (even though the file may never be created). Since Apache Ant 1.7 boolean No; defaults to false
createfile Whether the temp file should be created by this task. Since Ant 1.8 boolean No; defaults to false

Examples

Create a temporary file

<tempfile property="temp.file"/>

Create a temporary file with the .xml suffix

<tempfile property="temp.file" suffix=".xml"/>

Create a temporary file in the build subdirectory

<tempfile property="temp.file" destDir="build"/>