Share this page

# lr.read_file

Reads a file into a parameter.

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

String and Parameter Functions | Java Syntax

## Arguments

Name | Comments
--- | ---
filename | The full pathname or the pathname relative to the script folder.
outputParam | The name of the parameter that stores the file contents.
continueOnError | lr.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.

Copy code

    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: <code>{testparam}</code>

        //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

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: