Read from Text File
- Updated2023-02-17
- 4 minute(s) read
Read from Text File
Reads a specified number of bytes from a byte stream file.
Inputs/Outputs

prompt
Custom message in the title bar of the file dialog box that appears when you do not wire a value to the input path.

file path
The file that this node reads.
This input can be a reference to a file or an absolute file path. The node opens the specified file without requiring you to call Open/Create/Replace File first.
If you wire a path to file, this node opens the file before reading from it and closes it afterwards.
If you specify an empty path, a relative path, or a path to a non-existent file, this node returns an error.

count
The maximum number of data elements to read. Data elements are instances of the specified data type.
If this node reaches the end of the file before reading the specified number of data elements, the node returns the available data elements along with an end-of-file error.
If count is -1, the node reads the entire file, characters or lines, unless the size of the file is too large to be represented by a 32-bit integer. In this case, the node returns an error. If count is less than -1, the node returns an error.
Default value: 1

error in
Error conditions that occur before this node runs.
The node responds to this input according to standard error behavior.
Default value: No error

refnum out
A reference to the file that this node uses.

text
The string read from the file.

cancelled?
A Boolean value that indicates whether the user cancelled the dialog box that appears if no input file was wired to this node.
| True | The dialog box was cancelled. |
| False | The dialog box was not cancelled, or the dialog box did not appear. |

error out
Error information.
The node produces this output according to standard error behavior.
Programming Patterns
Configuring Read from Text File to Read Characters or Lines
By default, this node reads all characters from the text file. Wire an integer value to count to specify how many individual characters you want to read starting with the first character. Right-click the node and place a checkmark next to the Read Lines option in the shortcut menu to read individual lines from the text file. When you select the Read Lines option in the shortcut menu, wire an integer value tocount to specify how many individual lines you want to read from the file starting with the first line.
Read and Write Permissions for Read from Text File
This node opens files as read-only. This node returns a permissions error if you wire the refnum outoutput of this node to the file input of a write node. Use the Open/Create/Replace File node to open the file with the default read/write access and wire the refnum to the read and write nodes. Use the Set File Position node if you need to perform random access.Preventing Read from Text File from Converting End-of-Line Characters to Line Feed Characters
This node converts all platform-dependent end-of-line characters to line feed characters unless you right-click the node and remove the checkmark next to the Convert EOL shortcut menu item.