JavaScript Functions > Alphabetical Listing of Utility Functions (lr) > lr.readFile

lr.readFile

Reads a file into a parameter.

Java Language

lr.readFile( filename, output parameter name, continue on error );

Example String and Parameter Functions

Arguments

Name Comments
filename The full pathname or the pathname relative to the script folder.
output parameter name The name of the parameter that stores the file contents.
continue on error lr.EXIT_VUSER (0) or
lr.EXIT_ACTION_AND_CONTINUE (1)

lr.readFile 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

This action shows the usages of lr.readFile.

function Action()
{
    // EXIT_ACTION_AND_CONTINUE on error
	lr.readFile("test.txt","testparam", lr.EXIT_ACTION_AND_CONTINUE);
	lr.logMessage(lr.evalString("{testparam}"));
			
	// EXIT_VUSER on error
	lr.readFile("notfound2.txt","notfound2", lr.EXIT_VUSER);
			
    return 0;
}