I used Webdriver sampler and write selenium -Javascript.

Now I used org.apache.commons.io.FileUtils.writeStringToFile(new java.io.File('somefile.log'), 'some-data', 'UTF-8', true) function to write a file .

I want to save a tabular data (column & row-wise) in that file using writeStringToFile() function.

How we can achieve this?

2 Answers 2


If you want to insert a tabulation symbol - use \t escaped value

Here is an example of writing "tabular data" into JMeter log file

enter image description here

  • Actually, I want to save the file in .csv format and try to run multiple users and save result in a CSV file. so the column header is the same only row will change. How can we do this?
    – James P.
    May 20, 2022 at 13:19

To save tabular data in a file using the writeStringToFile() function from the org.apache.commons.io.FileUtils library, you can create a string with the tabular data in the desired format, and then pass that string as the second argument to the writeStringToFile() function.

For example, let's say you have the following tabular data:

enter image description here

You could represent this data in a string with the following format:

Column 1, Column 2, Column 3
Row 1, Column 1, Row 1, Column 2, Row 1, Column 3
Row 2, Column 1, Row 2, Column 2, Row 2, Column 3

This string represents the tabular data in a comma-separated format, where each row is separated by a new line character (\n) and each column is separated by a comma.

To write this string to a file, you can use the writeStringToFile() function as follows:

String tableData = "Column 1, Column 2, Column 3\n" +
                   "Row 1, Column 1, Row 1, Column 2, Row 1, Column 3\n" +
                   "Row 2, Column 1, Row 2, Column 2, Row 2, Column 3\n";
FileUtils.writeStringToFile(new File("table.txt"), tableData, StandardCharsets.UTF_8, true);

In this example, the tableData string contains the tabular data in the desired format, and the writeStringToFile() function writes this data to a file named "table.txt" using the UTF-8 character encoding and with the "append" flag set to true so that the data is added to the end of the file if it already exists.

For more information on the writeStringToFile() function and other file manipulation functions provided by the org.apache.commons.io.FileUtils library, you can refer to the library's documentation at: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.