LoadFile

Description

Load a text file into a single property. Unless an encoding is specified, the encoding of the current locale is used. There is no explicit limit upon the size of the file which can be loaded, but loading very large files is not something anyone has yet explored. Because the file is converted to text

Parameters

Attribute Description Required
srcFile source file Yes
property property to save to Yes
encoding encoding to use when loading the file No
failonerror Whether to halt the build on failure No, default "true"
evaluateProperties flag to enable property evalation in the file No, default "false"
makeOneLine flag to strip out newlines (but not spaces or tabs) from the file No, default "false"

The makeOneLine parameter enables you to use a file as an input to task parameters which expect single line input. It flattens the file by removing all carriage return and line feed characters, so that the file

a
b
c
would become "abc": you need spaces or commas at the end/start of line to stop alphanumeric characters being merged together.

Examples

    <loadfile property="message"
      srcFile="message.txt" / >
Load file message.txt into property "message"; an <echo> can print this.
    <loadfile property="encoded-file"
      srcFile="loadfile.xml"
      encoding="ISO-8859-1" / >
Load a file using the latin-1 encoding
    <loadfile
      property="optional.value"
      srcFile="optional.txt"
      failonerror="false" />
Load a file, don't fail if it is missing (a message is printed, though)
    <loadfile
      property="mail.recipients"
      srcFile="recipientlist.txt"
      makeOneLine="true" />
load a property which can be used as a parameter for another task (in this case mail), merging lines to ensure this happens.
    <loadfile
      property="system.configuration.xml"
      srcFile="configuration.xml"
      evaluateProperties="true" />
load an XML file into a property, expanding all properties declared in the file in the process.

Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.