1
votes

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

2

2 Answers

2
votes
  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()));
    
1
votes

To know file length in KB, use length() method:

long fileSizeInKB =  new File("fileName").length() / 1024;

The length, in bytes, of the file