Append data into a file using Apache Commons I/O

前端 未结 7 1604
野的像风
野的像风 2020-12-09 14:48

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 th

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 15:49

    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

    ex:

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

提交回复
热议问题