venkat sai
venkat sai

Reputation: 475

Jmeter, over writing data to file if it exists using jsr223 postProcessor

def file= new File(path + 'fileName.csv');
	List.unique().each { element ->
		file<< element << newLine
		}
Now the script is appending the file But i want to clear all the data and over write the fileName.csv if it already exists If the file doesn't exists, create the file and write data to file.

Upvotes: 0

Views: 1633

Answers (1)

Dmitri T
Dmitri T

Reputation: 168207

The easiest is to delete the file prior to writing to it via i.e. Files.deleteIfExists() function Add the next line to your script which will remove the file if it's present already:

java.nio.file.Files.deleteIfExists(file.toPath())

Full code just in case:

def file = new File(path + 'fileName.csv');
java.nio.file.Files.deleteIfExists(new File().toPath())
List.unique().each { element ->
    file << element << newLine
}

See The Groovy Templates Cheat Sheet for JMeter for more hints

Upvotes: 1

Related Questions