GroovyConsole I/O

yftpprvb  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(92)

我开始了一个项目,读取学生成绩的文件,并对该信息做一些计算。但我甚至无法找到允许用户输入文件名的语法。我找到了这个例子,但它抛出了一个错误。

class main
{
    static void main(args)
    {
        print ("Enter the name of the file: ");
        def fileName = System.console().readLine;
        println(fileName);
    }
}

字符串


的数据

inb24sb2

inb24sb21#

正如@cfrick已经在评论中提到的,readLine是一个函数/方法(你需要正确地调用它readLine())下面是工作代码:

class Main
{
    static void main(args)
    {
        print ("Enter the name of the file: ");
        def fileName = System.console().readLine();
        println(fileName);
    }
}

字符串
你可以阅读更多关于调用Groovy方法here的内容。

相关问题