title: How can I write ByteArrayOutput stream to a file in groovy?
body: <p>In Java, I can easily use following code, to write a <code>ByteArrayOutputStream</code> to a file. However, <code>try-with-resources</code> doesn't work in Groovy :( </p>
  
  <pre><code>ByteArrayOutputStream byteArrayOutputStream = getByteStreamMethod();
  try(OutputStream outputStream = new FileOutputStream("thefilename")) {
      byteArrayOutputStream.writeTo(outputStream);
  }
  </code></pre>
  
  <p>I have been trying to follow links like <a href="http://mrhaki.blogspot.co.uk/2009/11/groovy-goodness-readers-and-writers.html" rel="nofollow noreferrer">http://mrhaki.blogspot.co.uk/2009/11/groovy-goodness-readers-and-writers.html</a>
  and
  SO answer here <a href="https://stackoverflow.com/questions/17100806/intellij-error-java-try-with-resources-is-not-supported-in-source-1-6-error">IntelliJ error - java: try-with-resources is not supported in -source 1.6 error. Even though in project settings 1.7 JDK is selected</a></p>
  
  <p>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?</p>
  
  <p>PS: I am using Groovy <strong>v2.4.12</strong> </p>