Home>

I want to create a method that reads and outputs external .txt data line by line in Java.
Is there a mistake in the description in the method or the calling method in the main statement?

Error message
Error: (8, 9) java: cannot find symbol
  Symbol: Method masterFileLoader ()
  Location: Class issues.LoaderTest
Applicable source code
package input;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Loader {
    public void masterFileLoader () throws IOException {
        // Master file name
        final String masterFileName = "masterFile.txt";
        Path pathMasterFilename = Paths.get (masterFileName);
        BufferedReader readMasterFile
                = Files.newBufferedReader (pathMasterFilename, StandardCharsets.UTF_8);
        try {
            for (String line;(line = readMasterFile.readLine ())! = null;) {
                System.out.println (line);
            }
            readMasterFile.close ();
        } catch (IOException e) {
            System.out.println ("ERROR");
            System.out.println (e);
        }
    }
}
package input;
public class LoaderTest {
    public static void main (String [] args) {
        masterFileLoader ();
    }
}

When the contents of the masterFileLoader method are copied and executed in the Main statement, the desired operation (the contents of the txt file are output line by line) has been confirmed.

[Added]
In the Loader class
public Loader () {
}
And

package input;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Loader {
    // int readNum = 0;
    public Loader () {
    }
    public void masterFileLoader () throws IOException {
        // Master file name
        final String masterFileName = "masterFile.txt";
        Path pathMasterFilename = Paths.get (masterFileName);
        BufferedReader readMasterFile
                = Files.newBufferedReader
                (pathMasterFilename, StandardCharsets.UTF_8);
        for (String line;
             (line = readMasterFile.readLine ())! = null;) {
            System.out.println (line);
        }
        readMasterFile.close ();
    }
}


main statement
public class LoaderTest {
    public static void main (String [] args) throws IOException {
        Loader load = new Loader ();
        load.masterFileLoader ();
    }
}


It was possible to output by changing to

How to describe personal ideals

Is it ideal that it can be executed with the following description, is this possible?
How should I write a method if possible?

public class LoaderTest {
    public static void main (String [] args) throws IOException {
        masterFileLoader ();
    }
}
Supplemental information (FW/tool version etc.)

I use IntelliJ IDEA