1.

Write the code to write data stored in a JMeter variable to a CSV file.

Answer»

To WRITE data to a CSV file, use the lines of code below inside a BeanShell postprocessor.

 dataString = vars.get("DataToBeWritten");FILEPATH = vars.get("DataFilePath"); // you should pass true if you want to append the data to an existing file // if you wish to OVERWRITE, then do not pass the second argument FileWriter fstream = NEW FileWriter(filePath, true); BufferedWriter out = new BufferedWriter(fstream); out.write(dataString); out.write(System.getProperty("line.separator")); out.close(); fstream.close();

In the above code, the data is WRITTEN to an existing file. The path of the existing file is stored in filePath, and the data in dataString is appended to the file.



Discussion

No Comment Found