fileWrite

Version 24.2.9039


fileWrite


Write encoded data to a new or existing file.

Required Parameters

  • file: The full path (including the filename) of the file to write to. If the file does not exist, it is created.
  • data: The data to write to the file.

Optional Parameters

  • force: Controls whether the operation creates missing directories in the path set in the file parameter. The allowed values are true and false. The default is true.
  • mode: The mode of writing. The allowed values are truncate and append. The default is truncate, which overwrites the contents of the file if the target file already exists.
  • encoding: The encoding to use when creating the file. The allowed values are determined by your JVM/OS. The default is UTF-8.

Output Attributes

  • file:file: The full path of the file written to.
  • file:cdate: The modified date of the file.

Example

<!-- Setting the target file, mode and data on the input item. This example pulls data from existing message headers to append to a csv file. -->
<arc:set attr="input.file" value="/tmp/orders.csv"/>
<arc:set attr="input.mode" value="append" />
<arc:set attr="input.data">[header:orderno],[_|now('MM-dd-yyyy HH:mm')],[header:itemsku],[header:itemqty]\n</arc:set>

<!-- Calling fileWrite and passing in the input item -->
<arc:call op="fileWrite" in="input" out="result">
  <!-- Optional: Logging information about the modified file to the application log -->
  <arc:set attr="_log.info" value="The [result.file:file] file was updated at [result.file:cdate] with a new order."/>  
</arc:call>