Javatpoint Logo
Javatpoint Logo

Apache Ant Copy Task

This task is used to copy file or resource to a new location. It copies only if the source files is newer than the destination file. We can also explicitly overwrite it by using overwrite attribute.

The todir attribute is used to set the destination path. This task uses various attributes which are given below.

Apache Ant Copy Task Attributes

Attribute Description Required
file The file which is to be copied. Yes
preservelastmodified Preserve last modified name. No
tofile The file to copy to the destination file. if the file attribute is also specified, then only todir is allowed.
todir The destination directory name.
overwrite Overwrite existing files even if the destination files are newer. No
force Overwrite read-only destination files. No
filtering Filter during the copy. No
flatten Copy files by ignoring the directory structure of the source files. No
includeEmptyDirs Copy empty directories. No
failonerror Display error message if copy is failed. No
quiet If true and failonerror is false, then do not log a warning message. No
verbose It logs the files that are being copied. No
encoding Encoding for copying file. No
outputencoding Display the encoding to be used. No

Apache Ant Copy Task Example

Lets see an example in which we are copying data from one file to another. See the example below.

Copy single file

// build.xml

Copy file to directory

Copy directory to another directory





Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA