0

我尝试了不同的方法将字符串写入文件。

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

或者

file << xmlDocument

这样,文件大小达到1kb时的字符串就被中断了。

如果我这样做(如此处所述: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()

发生字符串重复。如何使用第一种方法而不限制字符串大小?谢谢

4

1 回答 1

1

Does:

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

work?

于 2012-07-23T12:15:32.680 回答