FileDocCategorySizeDatePackage
TempFile.javaAPI DocApache Ant 1.704131Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.taskdefs

TempFile

public class TempFile extends org.apache.tools.ant.Task
This task sets a property to the name of a temporary file. Unlike {@link 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.

Examples

<tempfile property="temp.file" />
create a temporary file
<tempfile property="temp.file" suffix=".xml" />
create a temporary file with the .xml suffix.
<tempfile property="temp.file" destDir="build"/>
create a temp file in the build subdir
since
Ant 1.5
ant.task

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
private String
property
Name of property to set.
private File
destDir
Directory to create the file in. Can be null.
private String
prefix
Prefix for the file.
private String
suffix
Suffix for the file.
private boolean
deleteOnExit
deleteOnExit flag
Constructors Summary
Methods Summary
public voidexecute()
Creates the temporary file.

exception
BuildException if something goes wrong with the build

        if (property == null || property.length() == 0) {
            throw new BuildException("no property specified");
        }
        if (destDir == null) {
            destDir = getProject().resolveFile(".");
        }
        File tfile = FILE_UTILS.createTempFile(
                prefix, suffix, destDir, deleteOnExit);

        getProject().setNewProperty(property, tfile.toString());
    
public booleanisDeleteOnExit()
Learn whether deleteOnExit is set for this tempfile task.

return
boolean deleteOnExit flag.

        return deleteOnExit;
    
public voidsetDeleteOnExit(boolean deleteOnExit)
Set whether the tempfile created by this task should be set for deletion on normal VM exit.

param
deleteOnExit boolean flag.

        this.deleteOnExit = deleteOnExit;
    
public voidsetDestDir(java.io.File destDir)
Sets the destination directory. If not set, the basedir directory is used instead.

param
destDir The new destDir value

        this.destDir = destDir;
    
public voidsetPrefix(java.lang.String prefix)
Sets the optional prefix string for the temp file.

param
prefix string to prepend to generated string

        this.prefix = prefix;
    
public voidsetProperty(java.lang.String property)
Sets the property you wish to assign the temporary file to.

param
property The property to set
ant.attribute
group="required"


                              
        
        this.property = property;
    
public voidsetSuffix(java.lang.String suffix)
Sets the optional suffix string for the temp file.

param
suffix suffix including any "." , e.g ".xml"

        this.suffix = suffix;