lr.read_file

Reads a file into a parameter.

C#

int lr.read_file( string <filename>, string <output parameter name>, int <continue on error>);

ExampleString and Parameter Functions

Arguments

NameComments
filenameThe full pathname or the pathname relative to the script folder.
output parameter nameThe name of the parameter that stores the file contents.
continue on errorlr.EXIT_VUSER (0) or
lr.EXIT_ACTION_AND_CONTINUE (1)

lr.read_file reads a file and saves the file contents in a parameter.

Return Values

This function returns the number of bytes read. On failure, returns a negative number.

Parameterization

Parameterization is not applicable to this function.

Example

These actions show the usages of lr.read_file.

public int action() throws Throwable {
    
    lr.read_file("test.txt","testparam", lr.EXIT_ACTION_AND_CONTINUE);
    lr.log_message(lr.eval_string("{testparam}"));
    // If file read, outputs file content. If not found or not read, outputs: {testparam}
    
    //not found with error
    lr.read_file("notfound.txt","notfound", lr.EXIT_VUSER);
    /* Log output:
       Error: can not open file
       Abort was called from an action.
       Ending Vuser...
    */
    
    return 0;
}//end of action