I run your first code and I didn't get any runtime exceptions.
And you don't have to use another Scanner and search line by line. The next() method of the Scanner will keep search in the next line if the current line has end.
What do think will print here..? 12.3456.. No, here you get that runtime error. But, if there weren't that abcd answer will be 12.3456
Scanner lineScanner = new Scanner(line);
while (lineScanner.hasNextDouble()){
System.out.print(lineScanner.next() + " " + "\n");
The text on the file do not contain double value in the first place, except the first line. Therefore
hasNextDouble() works only for first line.
So you have to keep searching for a double value, if find one print it. And if it is not the end of the file, keep doing that thing.
Actually, your question was to print the names, not the doubles. I think this may help.