Pietro
Pietro

Reputation: 1835

Java / Groovy&Grails File write

I have tried different ways to write a string to a file.

File file = new File(eventPath)
file.withWriterAppend { it << xmlDocument } 

OR

file << xmlDocument

In this way, the string when the file size reaches 1kb is interrupted.

If I do this way (as explained here: java: write to xml file)

File file = new File("foo")
if (file.exists()) {
    assert file.delete()
    assert file.createNewFile()
}

boolean append = true
FileWriter fileWriter = new FileWriter(file, append)
BufferedWriter buffWriter = new BufferedWriter(fileWriter)

100.times { buffWriter.write "foo" }

buffWriter.flush()
buffWriter.close()

Happens that the string gets repeated. How can I use the first method without have limit on string size? Thanks

Upvotes: 0

Views: 366

Answers (1)

tim_yates
tim_yates

Reputation: 171054

Does:

new File(eventPath).withWriterAppend { it.writeLine xmlDocument }

work?

Upvotes: 1

Related Questions