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