Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Read from Text File Function

LabVIEW 2010 Help

Edition Date: June 2010

Part Number: 371361G-01

»View Product Info

Owning Palette: File I/O VIs and Functions

Requires: Base Package

Reads a specified number of characters or lines from a byte stream file. This function does not work for files inside an LLB.

This function opens files as read-only. If you wire the refnum out output of this function to the file (use dialog) input of a write function, LabVIEW returns a permissions error. Use the Open/Create/Replace File function to open the file with the default read/write access and wire the refnum to the read and write functions.

Details  Example

prompt (Open existing file) is the message that appears above the list of files and directories, or folder, in the file dialog box.
file (use dialog) can be a refnum or absolute file path. If it is a path, this function opens the file specified by the path. The default is to display a file dialog box and prompt you to select a file.

If you specify an empty or relative path or if the file does not exist, this function returns an error.
count is the maximum number of characters or lines the function reads. The function reads fewer characters or lines if it reaches the end of file first. If count is <0, the function reads the entire file. The default is to read a single line if you placed a checkmark next to the Read Lines shortcut menu item and to read the entire file if you removed the checkmark next to the item.
If you wire a file size with a data type other than a 32-bit integer to count, LabVIEW coerces the data type to a 32-bit integer. This means the VI may not read the amount of data you intend. If you wire –1 to count and the size of the file you want to read is too large to be represented by a 32-bit integer, LabVIEW returns an error.
error in describes error conditions that occur before this node runs. This input provides standard error in functionality.
refnum out is the refnum of the file that the function read. You can wire this output to another file function, depending on what you want to do with the file. The default is to close the file if it is referenced by a file path or selected from the file dialog box. If file is a refnum or if you wire refnum out to another function, LabVIEW assumes that the file is still in use until you close it.
text is the text read from the file. By default, this parameter is a string that contains the characters read from the first line of the file. If you wire count, this parameter is an array of strings that contains the lines read from the file. If you right-click the function and remove the checkmark next to the Read Lines shortcut menu item, this parameter is a string that contains the characters read from the file.
cancelled is TRUE if you cancel the file dialog box. Otherwise, cancelled is FALSE, even if this function returns an error.
error out contains error information. This output provides standard error out functionality.

Read from Text File Details

By default, this function 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 function 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 to the count input to specify how many individual lines you want to read from the file starting with the first line. Enter a value of -1 in count to read all characters and lines from the text file.

Use the Set File Position function if you need to perform random access.

The function converts all platform-dependent end-of-line characters to line feed characters unless you right-click the function and remove the checkmark next to the Convert EOL shortcut menu item. If you wire a path to file, the function opens the file before reading from it and closes it afterwards.

Example

Refer to the Write-Read Text File VI in the labview\examples\general\functions\File IO directory for an example of using the Read from Text File function.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit