File lstFile = new File(lstFileName).withWriter{out->
archivedFiles.each {out.println it.name}
}
archivedFiles is a List objects .. I am getting an error that says:
Cannot cast object with class 'java.util.ArrayList' to class 'java.io.File'.
I am only interested in writing out file names contained in the list to the NEWLY created file
Groovy - add() Append the new value to the end of this List. This method has 2 different variants. boolean add(Object value) − Append the new value to the end of this List.
Since the path changes machine to machine, you need to use a variable / project level property, say BASE_DIRECTORY, set this value according to machine, here "/home/vishalpachupute" and rest of the path maintain the directory structure for the resources being used.
You can print the current value of a variable with the println function.
That's beacuse the withWriter
block is returning the last thing in the block by default (which is the archivedFiles
list)
To do what you're trying to do, you'd need to do:
File lstFile = new File(lstFileName)
lstFile.withWriter{ out ->
archivedFiles.each {out.println it.name}
}
or this should work too:
File lstFile = new File( lstFileName ).with { file ->
file.withWriter{ out ->
archivedFiles.each {out.println it.name}
}
file
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With