LoadFile

說明

loadresource 的特殊化,專門用於檔案,並提供 srcFile 屬性以方便使用。除非指定 encoding,否則會使用目前區域設定的編碼。

如果資源內容為空 (可能在處理 filterchain 之後),則不會設定屬性。

參數

屬性 說明 必要
srcFile 來源檔案
property 要儲存到的屬性
encoding 載入檔案時要使用的編碼
failonerror 是否在失敗時停止建置 否;預設 true
quiet 不顯示診斷訊息 (除非已使用 -verbose-debug 開關呼叫 Apache Ant) 或修改結束狀態以反映錯誤。將此設定為 true 表示將 failonerror 設定為 false自 Ant 1.7.0 起 否;預設 false

LoadFile 任務支援巢狀 FilterChain

範例

將檔案 message.txt 載入屬性 message<echo> 可以列印此屬性。

<loadfile property="message"
          srcFile="message.txt"/>

上述範例與下列範例相同

<loadresource property="message">
    <file file="message.txt"/>
</loadresource>

使用 Latin-1 編碼載入檔案

<loadfile property="encoded-file"
          srcFile="loadfile.xml"
          encoding="ISO-8859-1"/>

載入檔案,如果檔案不存在,則不要失敗 (不過會列印訊息)

<loadfile property="optional.value"
          srcFile="optional.txt"
          failonerror="false"/>

載入可作為另一個任務 (此例中為 mail) 參數的屬性,並合併行以確保執行此動作。

<loadfile property="mail.recipients"
          srcFile="recipientlist.txt">
    <filterchain>
        <striplinebreaks/>
    </filterchain>
</loadfile>

將 XML 檔案載入屬性,並在處理過程中擴充檔案中宣告的所有屬性。

<loadfile property="system.configuration.xml"
          srcFile="configuration.xml">
    <filterchain>
        <expandproperties/>
    </filterchain>
</loadfile>