getTextFileReader
(FintechOS Studio 20.2 and later)
Stores the content of a file from the file upload location in a WorkflowTextFileReader object which can be read as a string, either line-by-line or all-at-once.
Syntax
server.files.getTextFileReader(fileName: string, [encoding: string | codePage: number]): WorkflowTextFileReader
| Parameter | Description |
|---|---|
fileName
|
Unique internal ID of the file (real name). |
encodng (optional) |
File encoding. The default value is UTF-8. |
codPage (optional) |
Numeric code page of the file encoding. The default value is 0 (UTF-8 encoding). |
Return Value
Returns a WorkflowTextFileReader object that stores the file's content.
Properties
| Property | Returned Type | Description |
|---|---|---|
EOF
|
boolean |
readLine() method to read the file line-by-line. |
Methods
| Method | Returned Type | Description |
|---|---|---|
dispose()
|
void | Disposes the WorkflowTextFileReader object. |
readAllText()
|
string | Returns the file content in string format. |
readLine()
|
WorkflowTextFileLine | Saves the current line in a WorkflowTextFileLine object and advances the cursor to the next line. Use the WorkflowTextFileLine.text property to return the current line in string format.You can use this method in conjunction with the EOF property to read the file line-by-line. |
Examples
In this example:
- We store the largeFile_ddde85d9-ca38-42b8-b6b9-e5cc6bb4078c.txt file in an object called reader.
- We parse each line of the file in a variable called line and log it in the trace_roll.log file. For details on how to write to the trace_roll.log file, see log.
var reader = server.files.getTextFileReader("largeFile_ddde85d9-ca38-42b8-b6b9-e5cc6bb4078c.txt");
using(reader, function(){
// read one line at a time and log it in the trace_roll.log file
while(!reader.EOF){
var line = reader.readLine();
log(line.text);
};
});
In this example
- We store the smallFile_d02b2f36-b0ce-4b85-abe6-bffa55ddb429.txt file in an object called reader.
- We save the file content of the reader object in a variable called content and log it in the trace_roll.log file. For details on how to write to the trace_roll.log file, see log.
var reader = server.files.getTextFileReader("smallFile_d02b2f36-b0ce-4b85-abe6-bffa55ddb429.txt");
using(reader, function(){
// get all file content
var content = reader.readAllText();
log(content);
});