Scanner#nextLine
is a method. You need to add parenthesis. Replace
scan.nextLine;
with
scan.nextLine();
^
Also Scanner
uses hasNextLine
to check for subsequent lines. Calling scan.nextLine()
on an open file will eventually cause a NoSuchElementException
. Replace:
while ((inputLine = scan.nextLine()) != null) {
...
}
with
while (scan.hasNextLine()) {
inputLine = scan.nextLine();
lineList.add(inputLine);
}
Note that the first call to scan.nextLine()
causes the first line to be consumed without being written to the sorted output file. Remove or comment this line if you intend all words to be written to file.