Read File
Read File
Section titled “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.
How it works
Section titled “How it works”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(defaultutf-8), unless the file starts with a BOM, which wins. If accented characters look wrong, tryiso-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.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Path of the file to read. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
encoding | string | "utf-8" | File encoding: utf-8, iso-8859-1, utf-16, utf-32, us-ascii… See encoding. |
Output
Section titled “Output”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).
Common errors
Section titled “Common errors”| Message | Cause 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. |
Example
Section titled “Example”Read File path = asset("email_template.txt") → output: templateSet Variable name = body value = replace(template, "{name}", customer.name)Related activities
Section titled “Related activities”- Write File — write a text file.
- File Exists — check before reading.
- Append to File — add text without erasing what is there.