使用 Apache Commons I/O 将数据附加到文件中 [英] Append data into a file using Apache Commons I/O

查看:18
本文介绍了使用 Apache Commons I/O 将数据附加到文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apache Commons I/O 的 FileUtils.writeStringToFile(fileName, text) 函数覆盖文件中的先前文本.我想将数据附加到我的文件中.有什么办法可以同样使用 Commons I/O 吗?我可以使用 Java 中的普通 BufferedWriter 来做到这一点,但我对使用 Commons I/O 的情况感到好奇.

The FileUtils.writeStringToFile(fileName, text) function of Apache Commons I/O overwrites previous text in a file. I would like to append data to my file. Is there any way I could use Commons I/O for the same? I can do it using normal BufferedWriter from Java but I'm curious regarding the same using Commons I/O.

推荐答案

已在 Apache IO 2.1 版本中实现.要将字符串附加到文件中,只需将 true 作为函数中的附加参数传递:

It has been implemented in 2.1 version of Apache IO. To append string to the file just pass true as an additional parameter in functions:

  • FileUtils.writeStringToFile
  • FileUtils.openOutputStream
  • FileUtils.write
  • FileUtils.writeByteArrayToFile
  • FileUtils.writeLines

例如:

    FileUtils.writeStringToFile(file, "String to append", true);

这篇关于使用 Apache Commons I/O 将数据附加到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆