In Java, I can easily use following code, to write a ByteArrayOutputStream
to a file. However, try-with-resources
doesn't work in Groovy :(
ByteArrayOutputStream byteArrayOutputStream = getByteStreamMethod();
try(OutputStream outputStream = new FileOutputStream("thefilename")) {
byteArrayOutputStream.writeTo(outputStream);
}
I have been trying to follow links like http://mrhaki.blogspot.co.uk/2009/11/groovy-goodness-readers-and-writers.html and SO answer here IntelliJ error - java: try-with-resources is not supported in -source 1.6 error. Even though in project settings 1.7 JDK is selected
but I am not able to think of Groovy syntax, to write above java code block as. Could you please do a little handholding here as to how to write above java code block in Groovy?
PS: I am using Groovy v2.4.12