ClaudioM
ClaudioM

Reputation: 1446

jmeter JSR223 groovy overwrite file

I've created a new file to write some information:

import org.apache.jmeter.services.FileServer;
out = new FileOutputStream("myfilePathName", true);
String outAggr="";
out << outAggr;
out.close();

I need to overwrite it or clear it before to add new information (out << outAggr). I don't want to create another file each time.

I've already tried to:

out < outAggr;
out < "";

but I got an exception

Can you help me with this?

Upvotes: 1

Views: 1836

Answers (2)

tim_yates
tim_yates

Reputation: 171154

If you want to overwrite any existing contents, you can just do:

new File("myfilePathName").text = ''

Upvotes: 2

Ori Marko
Ori Marko

Reputation: 58862

To override file you need to call newWriter, for example:

String outAggr="";
writer = new File(myfilePathName).newWriter("UTF-8", true)
writer.write(outAggr)
writer.close()

newWriter() methods have been added. It's now possible to specify the encoding used to write files, and optionnaly to specify wether we're in append mode.

Upvotes: 1

Related Questions