fileRead

Version 26.1.9568


fileRead


Reads the contents of an input file and pushes the data out as an attribute on the output item.

Required Parameters

  • file: The name of the file to read.

Optional Parameters

  • encoding: The strategy used to convert the file’s raw bytes into a string. If a standard charset (UTF-8, ASCII, etc) is provided, the operation will decode the supplied bytes using the provided charset. If a binary value such as (BASE64, HEX, etc) is provided, the operation will encode the raw bytes using the provided value. Values for the encoding parameter that are generally supported by most operating systems and JVMs include UTF-8, ASCII, BASE64, HEX, windows-1252, and ISO-8859-2. The default is UTF-8.

Output Attributes

  • file:data: The data from the input file.

Examples

Change the Encoding of an Input File

<!-- Creating the input item and setting the file and encoding attributes -->
<arc:set attr="input.file" value="[FilePath]" />
<arc:set attr="input.encoding" value="BASE64" />
<!-- Calling fileRead and passing in the input item -->
<arc:call op="fileRead" in="input" out="result" >
  <!-- The file:data here is now BASE64 encoded based on the value set in input.encoding -->
  <arc:set attr="fileOut.data" value="[result.file:data]" />
</arc:call>

<!-- Checking to make sure the output file has data, else throw an error -->
<arc:check attr="fileOut.data" >
  <arc:set attr="fileOut.filename" value="[FileName]" />
  <arc:push item="fileOut" />
  <arc:else>
    <arc:throw code="NoData" desc="No file data." />
  </arc:else>
</arc:check>

Replace Commas with Pipe Characters ( | )

<!-- Creating the input item and setting the file attribute -->
<arc:set attr="input.file" value="[FilePath]" />
<!-- Calling fileRead and passing in the input item -->
<arc:call op="fileRead" in="input" out="result">]
  <!-- Replacing all commas in the file with pipes and setting the new data on the output item -->
  <arc:set attr="output.data" value="[result.file:data | replace(',','|')]" />
</arc:call>

<!-- Checking to make sure the output file has data, else throw an error -->
<arc:check attr="output.data" >
  <arc:set attr="output.filename" value="[FileName]" />
  <arc:push item="output" />
  <arc:else>
    <arc:throw code="NoData" desc="No file data." />
  </arc:else>
</arc:check>