Search code examples
jmeterfilesizefilewriterbeanshell

JMeter Beanshell Get Text File Size Save to Variable


In Beanshell Post Processor I am creating a file and writing variable data received from a JDBC request to that file. I need to capture the file size of the created text file in KB and save to a variable so that I can call in a subsequent JDBC request.

Create File

Use FileSize in JDBC request variable


Solution

    1. Since JMeter 3.1 you should stop using Beanshell for scripting and switch to Groovy language.
    2. Don't inline JMeter Functions or Variables inside scripts as they might resolve into something causing compilation failure or unexpected behavior or will be resolved only once.

    3. You can save the size of the file into a JMeter Variable as:

      vars.put("fileSize", String.valueOf(new File("/path/to/file").length().toString()));