You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

loadfile.html 4.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  18. <title>LoadFile Task</title>
  19. </head>
  20. <body>
  21. <h2><a name="loadfile">LoadFile</a></h2>
  22. <h3>Description</h3>
  23. <p>
  24. Specialization of <a href="loadresource.html">loadresource</a> that
  25. works on files exclusively and provides a srcFile attribute for
  26. convenience. Unless an encoding is specified, the encoding of the
  27. current locale is used.
  28. </p>
  29. <p>If the resource content is empty (maybe after processing a filterchain)
  30. the property is not set.</p>
  31. <h3>Parameters</h3>
  32. <table border="1" cellpadding="2" cellspacing="0">
  33. <tr>
  34. <td valign="top"><b>Attribute</b></td>
  35. <td valign="top"><b>Description</b></td>
  36. <td align="center" valign="top"><b>Required</b></td>
  37. </tr>
  38. <tr>
  39. <td valign="top">srcFile</td>
  40. <td valign="top">source file</td>
  41. <td valign="top" align="center">Yes</td>
  42. </tr>
  43. <tr>
  44. <td valign="top">property</td>
  45. <td valign="top">property to save to</td>
  46. <td valign="top" align="center">Yes</td>
  47. </tr>
  48. <tr>
  49. <td valign="top">encoding</td>
  50. <td valign="top">encoding to use when loading the file</td>
  51. <td align="center" valign="top">No</td>
  52. </tr>
  53. <tr>
  54. <td valign="top">failonerror</td>
  55. <td valign="top">Whether to halt the build on failure</td>
  56. <td align="center" valign="top">No, default "true"</td>
  57. </tr>
  58. <tr>
  59. <td valign="top">quiet</td>
  60. <td valign="top">Do not display a diagnostic message (unless Ant has been
  61. invoked with the <code>-verbose</code> or <code>-debug</code>
  62. switches) or modify the exit status to reflect an error. Setting this to
  63. "true" implies setting failonerror to "false".
  64. <em>Since Ant 1.7.0.</em>
  65. </td>
  66. <td align="center" valign="top">No, default "false"</td>
  67. </tr>
  68. </table>
  69. <p>
  70. The LoadFile task supports nested <a href="../CoreTypes/filterchain.html">
  71. FilterChain</a>s.
  72. <h3>Examples</h3>
  73. <pre> &lt;loadfile property="message"
  74. srcFile="message.txt"/&gt;
  75. </pre>
  76. Load file message.txt into property "message"; an <tt>&lt;echo&gt;</tt>
  77. can print this. This is identical to
  78. <pre> &lt;loadresource property="message"&gt;
  79. &lt;file file="message.txt"/&gt;
  80. &lt;/loadresource&gt;
  81. </pre>
  82. </p>
  83. <pre> &lt;loadfile property="encoded-file"
  84. srcFile="loadfile.xml"
  85. encoding="ISO-8859-1"/&gt;
  86. </pre>
  87. Load a file using the latin-1 encoding
  88. <pre> &lt;loadfile
  89. property="optional.value"
  90. srcFile="optional.txt"
  91. failonerror="false"/&gt;
  92. </pre>
  93. Load a file, don't fail if it is missing (a message is printed, though)
  94. <pre> &lt;loadfile
  95. property="mail.recipients"
  96. srcFile="recipientlist.txt"&gt;
  97. &lt;filterchain&gt;
  98. &lt;<a href="../CoreTypes/filterchain.html#striplinebreaks">striplinebreaks</a>/&gt;
  99. &lt;/filterchain&gt;
  100. &lt;/loadfile&gt;
  101. </pre>
  102. Load a property which can be used as a parameter for another task (in this case mail),
  103. merging lines to ensure this happens.
  104. <pre> &lt;loadfile
  105. property="system.configuration.xml"
  106. srcFile="configuration.xml"&gt;
  107. &lt;filterchain&gt;
  108. &lt;<a href="../CoreTypes/filterchain.html#expandproperties">expandproperties</a>/&gt;
  109. &lt;/filterchain&gt;
  110. &lt;/loadfile&gt;
  111. </pre>
  112. Load an XML file into a property, expanding all properties declared
  113. in the file in the process.
  114. </body>
  115. </html>