Forum Discussion
SmartBear_Suppo
Alumni
13 years agoI believe this is a bug (unless we want to limit writes by design, but I don't think so).
Until we fix it, you can use Groovy scripts to change values in the file. Unless the file is being used concurrently by another process or task (which you should probably avoid anyway), rewriting the file from scratch is not such a big problem, and is probably quite easy to do in Groovy. For example. Here's how you'd replace all occurrences of the String "Enzo" with "Mario" in the file "data.txt":
def dataFile = new File("data.txt")
dataFile.text = dataFile.text.replaceAll("Enzo", "Mario")
Ahhh, it's so much nicer to do these things in Groovy than in Java! :-)
Of course, you need to be careful so you don't modify too much, so in the end you may want to read and parse lines individually. In that case you may want to use code like this.
def dataFile = new File("data.txt")
def buffer = new StringBuilder()
dataFile.eachLine { line ->
// inside this loop, the line will be available in the variable line, so you can process them individually, e.g.
def processedLine = "*** " + line + "\r\n"
buffer.append(processedLine)
}
dataFile.text = buffer.toString()
Kind regards,
Manne
Until we fix it, you can use Groovy scripts to change values in the file. Unless the file is being used concurrently by another process or task (which you should probably avoid anyway), rewriting the file from scratch is not such a big problem, and is probably quite easy to do in Groovy. For example. Here's how you'd replace all occurrences of the String "Enzo" with "Mario" in the file "data.txt":
def dataFile = new File("data.txt")
dataFile.text = dataFile.text.replaceAll("Enzo", "Mario")
Ahhh, it's so much nicer to do these things in Groovy than in Java! :-)
Of course, you need to be careful so you don't modify too much, so in the end you may want to read and parse lines individually. In that case you may want to use code like this.
def dataFile = new File("data.txt")
def buffer = new StringBuilder()
dataFile.eachLine { line ->
// inside this loop, the line will be available in the variable line, so you can process them individually, e.g.
def processedLine = "*** " + line + "\r\n"
buffer.append(processedLine)
}
dataFile.text = buffer.toString()
Kind regards,
Manne