Apache Ant 任務 - LoadFile



說明

Loadfile 任務載入檔案並將它的內容設定到屬性中。

屬性

序號 屬性和說明
1

srcFile

原始檔。

2

Property

要儲存到的屬性。

3

Encoding

在載入檔案時使用的編碼。

4

failonerror

是否在失敗時停止構建。

5

Quiet

不顯示診斷訊息(除非使用 -verbose 或 -debug 開關呼叫 Apache Ant)或修改退出狀態以反映錯誤。設定此選項為 true 意味著將 failonerror 設定為 false。

用法

建立 message.txt 並輸入以下內容 −

Welcome to tutorialspoint.com

示例

建立 build.xml 並輸入以下內容 −

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

輸出

在上述構建檔案中執行 Ant 會生成以下輸出 −

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

info:
   [echo] Welcome to tutorialspoint.com

BUILD SUCCESSFUL
Total time: 0 seconds
廣告