Apache Ant Tasks 简明教程
Apache Ant Tasks - Concat
Description
Concat 任务将一个或多个资源连接到单个文件或控制台。如果目标文件不存在,则创建该文件,除非资源列表为空且 ignoreempty 标志为 true。
Concat task concatenate one or more resources to a single file or to console. The destination file is created if it does not exist unless the resource list is empty and ignoreempty flag is true.
Properties
Sr.No |
Attributes & Description |
1 |
Destfile The destination file for the concatenated stream. If not specified the console will be used instead. |
2 |
Append Specifies whether or not the file specified by destfile should be appended. |
3 |
Overwrite Specifies whether or not the file specified by destfile should be written to even if it is newer than all source files. |
4 |
ForceReadonly Overwrite read-only destination files. |
5 |
Encoding Specifies the encoding for the input files. |
6 |
Outputencoding The encoding to use when writing the output file. |
7 |
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. |
8 |
EOL Specifies what the end of line character are for use by the fixlastline attribute. |
9 |
Binary 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. |
10 |
Filterbeforeconcat If this attribute is set to true, the task applies the filterchain to each input after applying fixlastline. If this attribute is false, concat will apply the filterchain only once to the already concatenated inputs. Filtering of header and footer is not affected by this setting. |
11 |
Ignoreempty Specifies whether or not the file specified by destfile should be created if the source resource list is empty. |
12 |
Resourcename Specifies the name reported if this task is exposed as a resource. |
Example
Usage
使用以下内容创建 build.xml −
Create build.xml with the following content −
<?xml version="1.0"?>
<project name="TutorialPoint" default="info">
<target name="info">
<concat>
<fileset dir="messages" includes="*test*"/>
</concat>
</target>
</project>
上述脚本将读取 messages 文件夹并在名称中具有 test 的文件的连接内容显示在控制台上。
Above script will read messages folder and concatenates contents of file having test in their name and show them on console.
Output
我们在 messages 文件夹中使用内容“Welcome to tutorialspoint.com”创建 test.txt。现运行上述构建文件中的 Ant 会生成以下输出 −
Let’s create a test.txt with content as "Welcome to tutorialspoint.com" in messages folder. Now running Ant on the above build file produces the following output −
F:\tutorialspoint\ant>ant
Buildfile: F:\tutorialspoint\ant\build.xml
info:
[concat] Welcome to tutorialspoint.com
BUILD SUCCESSFUL
Total time: 0 seconds