java left logo
java middle logo
java right logo

Home arrow Other API Tips
Main Menu
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog

Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews

Registered Users: 4116
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
How to use Concat task E-mail
User Rating: / 5



Concatenates a file, or a series of files, to a single file or the console. The destination file will be created if it does not exist.

Paths and/or FileSets and/or FileLists are used to select which files are to be concatenated. There is no singular 'file' attribute to specify a single file to cat.


Attribute Description Required
destfile The destination file for the concatenated stream. If not specified the console will be used instead. No
append Specifies whether or not the file specified by 'destfile' should be appended. Defaults to "no". No
force Specifies whether or not the file specified by 'destfile' should be written to even if it is newer than all source files. since Ant 1.6. Defaults to "yes". No
encoding Specifies the encoding for the input files. Please see for a list of possible values. Defaults to the platform's default character encoding. No
outputencoding The encoding to use when writing the output file since Ant 1.6. Defaults to the value of the encoding attribute if given or the default JVM encoding otherwise. No
fixlastline Specifies whether or not to check if each file concatenated is terminated by a new line. If this attribute is "yes" a new line will be appended to the stream if the file did not end in a new line. since Ant 1.6. Defaults to "no". This attribute does not apply to embedded text. No
eol Specifies what the end of line character are for use by the fixlastline attribute. since Ant 1.6 Valid values for this property are:
  • cr: a single CR
  • lf: a single LF
  • crlf: the pair CRLF
  • mac: a single CR
  • unix: a single LF
  • dos: the pair CRLF
The default is platform dependent. For Unix platforms, the default is "lf". For DOS based systems (including Windows), the default is "crlf". For Mac OS, the default is "cr".
binary since ant 1.6.2 If this attribute is set to true, the task concatenates the files in a byte by byte fashion. If this attribute is false, concat will not normally work for binary files due to character encoding issues. If this option is set to true, the destfile attribute must be set, and the task cannot used nested text. Also the attributes encoding, outputencoding, filelastline cannot be used. The default is false. No

Parameters specified as nested elements


since Ant 1.6.

This is a Path. This is used to select file files to be concatenated. Note that a file can only appear once in a path. If this is an issue consider using multiple paths.


FileSets are used to select files to be concatenated. Note that the order in which the files selected from a fileset are concatenated is not guaranteed. If this is an issue, use multiple filesets or consider using filelists.


FileLists are used to select files to be concatenated. The file ordering in the files attribute will be the same order in which the files are concatenated.


since Ant 1.6.

The concat task supports nested FilterChains.


since Ant 1.6.

Used to prepend or postpend text into the concatenated stream.

The text may be in-line or be in a file.

Attribute Description Required
filtering Whether to filter the text provided by this sub element, default is "yes". No
file A file to place at the head or tail of the concatenated text. No
trim Whether to trim the value, default is "no" No
trimleading Whether to trim leading white space on each line, default is "no" No


Concatenate a string to a file:

  <concat destfile="README">Hello, World!</concat>


Concatenate a series of files to the console:

    <fileset dir="messages" includes="*important*"/>


Concatenate a single file, appending if the destination file exists:

  <concat destfile="NOTES" append="true">

    <filelist dir="notes" files="note.txt"/>

Concatenate a series of files, update the destination file only if is older that all the source files:

  <concat destfile="${docbook.dir}/all-sections.xml"
    <filelist dir="${docbook.dir}/sections" 

    <fileset dir="${docbook.dir}" 

Concatenate a series of files, expanding ant properties

   <concat destfile="${build.dir}/subs">
        <fileset dir="${src.dir}" includes="*.xml"/>
        <pathelement location="build.xml"/>


Filter the lines containing project from build.xml and output them to report.output, prepending with a header

   <concat destfile="${build.dir}/report.output">
      <header filtering="no" trimleading="yes">
          Lines that contain project
      <path path="build.xml"/>

           <contains value="project"/>


Concatenate a number of binary files.

   <concat destfile="${build.dir}/dist.bin" binary="yes">
     <fileset file="${src.dir}/scripts/">
     <fileset file="${build.dir}/dist.tar.bz2">


Source: Apache Ant

 Related Tips

< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.

Name (required)

E-Mail (required)

Your email will not be displayed on the site - only to our administrator

Comment Enable HTML code : Yes No

java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008
Java is a trademark of Sun Microsystems, Inc.