Apache Ant Tasks 简明教程

Apache Ant Tasks - LoadFile

Description

Loadfile 任务将载入文件并将内容设置为属性。

Loadfile task loads a file and sets its content into property.

Properties

Sr.No

Attributes & Description

1

srcFile Source File.

2

Property Property to save to.

3

Encoding Encoding to use when loading the file.

4

failonerror Whether to halt the build on failure.

5

Quiet Do not display a diagnostic message (unless Apache Ant has been invoked with the -verbose or -debug switches) or modify the exit status to reflect an error. Setting this to true implies setting failonerror to false.

Usage

使用以下内容创建 message.txt −

Create message.txt with the following content −

Welcome to tutorialspoint.com

Example

使用以下内容创建 build.xml −

Create build.xml with the following content −

<?xml version="1.0"?>
<project name="TutorialPoint" default="info">
   <loadfile property="message" srcFile="message.txt"/>
   <target name="info">
      <echo message="${message}"/>
   </target>
</project>

Output

在上述构建文件上运行 Ant 会生成以下输出:

Running Ant on the above build file produces the following output −

F:\tutorialspoint\ant>ant
Buildfile: F:\tutorialspoint\ant\build.xml

info:
   [echo] Welcome to tutorialspoint.com

BUILD SUCCESSFUL
Total time: 0 seconds