title: Is there a way to reopen an input stream with withReader? - Groovy
body: <p>I know that the input stream is automatically closed at the end of this kind of block in Groovy:</p>
  
  <pre><code>def exec = ""
  System.in.withReader {
      println  "input: "
      exec = it.readLine()        
  } 
  </code></pre>
  
  <p>but is there a way to reopen the stream if I want to do something like that:</p>
  
  <pre><code>def exec = ""
  while(!exec.equals("q")) {   
      System.in.withReader {
          println  "input: "
          exec = it.readLine()        
      } 
      if(!exec.equals("q")) {
          //do something
      }
  }
  </code></pre>
  
  <p>When I try this I get this error at the second execution of the while loop:</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Stream closed
  </code></pre>
  
  <p>So what would be the best way to achieve that?</p>
  
  <p>Thanks. </p>