There is a writeToFile method that writes the necessary data to a .txt file, the problem is that the text is overwritten each time, but I need to be added.

public void writeToFile(def directory, def fileName, def extension, def infoList) { new File("$directory/$fileName$extension").withWriter { out -> infoList.each { out.println it } 

and here is the code on which I test the method

 def directory = 'C:/Task_1' def c def txtFileInfo = [] txtFileInfo << "Ваши данные - ${U_id}" txtFileInfo << "И ваши данные... - ${B_num}" writeToFile(directory, "info", ".txt", txtFileInfo 

    1 answer 1

     new File("$directory/$fileName$extension").withWriterAppend { ... } 
    • I understood correctly? public void writeToFile(def directory, def fileName, def extension, def infoList) { new File("$directory/$fileName$extension").withWriterAppend { infoList.each { out.println it } } } - Alex
    • Yes, just replace the withWriterAppend with withWriterAppend . - Sergey Gornostaev
    • I get the error 'groovy.lang.MissingPropertyException: No such property: out for class: 1' - Alex