GroovyConsole I/O

41 views Asked by At

I am starting a project to read a file of student grades and do some calculations on that information. But I cannot even manage to find syntax that would allow for the user to input a file name. I found this example but it throws an error.

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

This is the console output.

1

There are 1 answers

1
Andrej Istomin On

As @cfrick is already mentioned in the comment, readLine is a function/method (you need to call it properly readLine()) Here is the working code:

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

You may read more about calling Groovy methods here.