How to write to a file with JMeter

Creating files from your script during runtime and finding it after your flood

There are several reasons why you might need the ability to write to a file during runtime. For example, maybe you'd like to save your results as a .jtl file. Luckily, this is very easy to do with Flood. ​ All you have to do is modify your script to create the .jtl file by adding a listener such as the Simple Data Writer and using the absolute path /data/flood/results/ like this:​

This will ensure that the .jtl is created after your test is executed.

If you want to write something other than results to a file in JMeter, you can use BeanShell to add code. You can do this by adding a BeanShell Sampler, BeanShell Preprocessor or BeanShell Postprocessor to your test plan and using something like this to create the file and populate it:

FileWriter f = new FileWriter("PATH_HERE/accountscreated.csv",true);
BufferedWriter out = new BufferedWriter(f);
out.write(vars.get("accountNumber") + "\n");
out.close();
f.close();

​ Either way, once the test is executed on Flood, you'll be able to download the file after the test as part of your Archived Results.

If you're still having trouble with this, please give us a yell via email or live chat and we'll gladly help you out.

Last updated