fileReadLine

Version 23.4.8839


fileReadLine


Reads and enumerates over the contents of an input file on a line-by-line basis and pushes the data out as an output attribute.

Required Parameters

  • file: The name of the file to read.

Optional Parameters

  • separator: The character separator that determines each new line. The default value is the newline character (\n).
  • encoding: The encoding to use. The allowed values are determined by the JVM/OS being used. Values for encodings that are generally supported by most operating systems and JVMs include UTF-8, ASCII, BASE64, windows-1252, and ISO-8859-2. The default is UTF-8.

Output Attributes

  • file:line: The line number of the file.
  • file:data: The data from the input file.

Example

This example replaces some data from the first line only.

<!-- Creating the input item and setting the file attribute -->
<arc:set attr="input.file" value="[FilePath]" />
<!-- Initializing the item to hold the file data minus the first line -->
<arc:set attr="restof.data" value="" />
<!-- Calling the fileReadLine operation and passing in the input item -->
<arc:call op="fileReadLine" in="input" out="result" >
  <!-- Once the operation gets to the first line in the file, perform a replace -->
  <arc:if exp="[result.file:line] == 1">
    <arc:set attr="first.line" value="[result.file:data | replace('ArcESB','CData Arc')]" />
    <arc:else>
      <!-- Setting the data for the output file to be the concatenation of the modified first line and the rest of the file data -->
      <arc:set attr="output.data" value="[first.line][restof.data]\n[result.file:data]" />
    </arc:else>
  </arc:if> 
</arc:call>
<arc:set attr="output.filepath" value="[FilePath]" />
<arc:push item="output" />