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 3.9 KiB

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