I\'m just starting to learn Groovy and I am experimenting in GroovyConsole.
Is there a way I can read user input? I have tried the code below but I get an error.
You could try something like this, which works at the command-line of any o/s, but also in the GoovyConsole - where it pops up a dialog [as noted in a previous post]:
def cons = System.console()
def yn
if (cons) {
yn = {((cons.readLine(it + " (y/n) ")?:"n").trim()?:"n")?.charAt(0).toLowerCase().toString() }
} else {
cons = javax.swing.JOptionPane.&showInputDialog
yn = {((cons(it + " (y/n) ")?:"n").trim()?:"n")?.charAt(0).toLowerCase().toString() }
}
if (yn("Did you want to do something?") == 'y')
...do something here!...