Read External Files (Text Files)

Soley Studio offers several library functions and procedures to create and interact with external files. An overview of these functions is provided in the IO library elements article. You can find all the IO library elements in the respective section of the Libraries Pad in Soley Studio.

This article shows how to read from an external file. The most commonly used external files are text files such as .txt or .csv files, but the system is not limited to that.

The IO library offers two different functions to read from an external file: IO_readFileText() and IO_readFileLines().

IO_readFileText

IO_readFileText(FILE_NAME) receives as an input the full path to the file and outputs the content of the file as a single string.

Example:

sequence readFileText_demo{  
     CONTENT:string ;>
     {CONTENT = IO_readFileText(IO_getProjectPath() + "\\Hello.txt")} ;>  
     {emit(CONTENT + "\n")}  
 }

IO_readFileLines

IO_readFileLines(FILE_NAME) receives as an input the full path to the file and outputs the content of the file as an array of strings. This means that every string of the newly built array will correspond to one line of the file.

Example:

 sequence readFileLines_demo{  
         LINE_ARRAY:array<string> = array<string>[] ;>
         {LINE_ARRAY = IO_readFileLines(IO_getProjectPath() + "\\Hello.txt")} ;>  
         {emit(LINE_ARRAY + "\n")}  
 }

Was this article helpful?

Related Articles