fileRead

Version 23.4.8839


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 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:data: The data from the input file.

Examples

Change the Encoding of an Input File

<!-- Creating the input item and setting the file attribute -->
<arc:set attr="input.file" value="[FilePath]" />
<!-- Calling fileRead and passing in the input item and setting the encoding of the output -->
<arc:call op="fileRead" in="input" out="result" >
  <arc:set attr="fileOut.encoding" value="BASE64" />
  <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>