Opening, Processing, and Closing Files
- Updated2023-02-17
- 2 minute(s) read
Opening, Processing, and Closing Files
What to Use
- Open/Create/Replace File
- A read or write node from the Storage palette category
- Close File
What to Do
Create the following diagram to programmatically open, write to, and close a text file.
Customize the gray sections for your unique programming goals.

|
Open, create, or replace a file by using the Open/Create/Replace File node and specifying its precise behavior. To access the enumerated list of possible behaviors, create a constant from the operation input of the node. |
|
After the file opens, a unique identifier called a refnum represents the file. A file refnum is required for most nodes that process files. |
|
Process the file by using a file I/O node from the Storage palette category. You can interact with binary or text files. In this example, Write to Text File writes Hello world to the file represented by the file refnum. |
|
Close the file to release the object from memory and avoid potential errors. If you do not close a file, the reference cannot be closed until the VI that opened the file finishes executing. |
Troubleshooting
- Some file I/O nodes are considered high-level nodes and perform all three steps of a file I/O process—open, read/write, and close. Avoid placing high-level file I/O nodes, such as Read from Spreadsheet File and Write to Spreadsheet File, in loops because these nodes perform open and close operations each time they run.