Groovy Console read input

后端 未结 5 666
闹比i
闹比i 2021-02-01 05:27

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.

5条回答
  •  悲&欢浪女
    2021-02-01 06:04

    Your code works.

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
    print "Input:"
    def userInput = br.readLine()
    println "You entered: $userInput"
    

    Assuming you're on windows, the only problem is that the input is being read from the console in the background that is launched before groovyconsole. enter image description here

提交回复
热议问题