Skip to content

Read File

Type: read-file  ·  Package: Filesystem Activities v1.0.6  ·  Output: string

Reads the whole content of a text file and returns it as a string. Use it to read .txt files, templates, logs, settings or any plain-text content.

Opens the file at the given path and returns its whole content as a single string, line breaks included. If the file does not exist, the activity fails.

  • Encoding: uses encoding (default utf-8), unless the file starts with a BOM, which wins. If accented characters look wrong, try iso-8859-1. See encoding.
  • All in memory: it loads the whole file; for very large files (hundreds of MB) consider splitting them.
  • Read-only: it does not change the file.
ParameterTypeDefaultDescription
pathstring—Path of the file to read.
ParameterTypeDefaultDescription
encodingstring"utf-8"File encoding: utf-8, iso-8859-1, utf-16, utf-32, us-ascii… See encoding.

Returns a string with the file content. An empty file returns "". To work line by line, split it with content.Split('\n') and clean each line with .Trim() (on Windows, lines end in \r\n).

MessageCause and fix
File not found.path does not exist. Check it first with File Exists or wrap the read in Try / Catch.
The process cannot access the file '…' because it is being used by another process.Another program has the file locked for writing.
Access to the path '…' is denied.No read permission, or path is a folder.
'windows-1252' is not a supported encoding name…The encoding is not available. Use iso-8859-1.
'path' is required.The path expression evaluated to null.
Read File path = asset("email_template.txt") → output: template
Set Variable name = body value = replace(template, "{name}", customer.name)