为什么这段代码不能读取我的文件?

use*_*070 0 java file-io exception

这是我从文本文件中读取的代码:

    public RecordManager(){
    int pos;
    String athlete, record, country, raceTime;
    try {
        Scanner scFile = new Scanner(new File("resultdata.txt"));
        while(scFile.hasNext()){
            Scanner sc = new Scanner(scFile.next()).useDelimiter("#");
            athlete = sc.next();
            country = sc.next();
            pos = sc.nextInt();
            record = sc.next();
            raceTime = sc.next();                
            sc.close();
            if("WRC".equals(record)){
                resultArr[size] = new WorldRecord(athlete, country, pos, raceTime);
            }
            else if("OLR".equals(record)){
                resultArr[size] = new OlympicRecord(athlete, country, pos, raceTime);
            }
            else{
                resultArr[size] = new RaceResult(athlete, country, pos, raceTime);
            }
            size++;
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RecordManager.class.getName()).log(Level.SEVERE, null, ex);
    }
Run Code Online (Sandbox Code Playgroud)

这是文本文件中的内容:

Carey Blem#ITA#6#---#4m49.8 
Tammera Hoesly#POR#1#---#4m6.2 
Toi Swauger#FRA#1#OLR#51.3 
Moises Mellenthin#ZIM#2#---#4m34 
Madelene Mcclennon#LUX#1#WRC#1m52.7 
Lashon Meisenheimer#RSA#1#---#2m31.2
Run Code Online (Sandbox Code Playgroud)

我一直在尝试和尝试,但我只是继续这样做:

run:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1416)
at it.practical.training.RecordManager.<init>(RecordManager.java:29)
at it.practical.training.SimpleInterface.main(SimpleInterface.java:20)
Java Result: 1
BUILD SUCCESSFUL (total time: 13 seconds)
Run Code Online (Sandbox Code Playgroud)

请告诉我出了什么问题.

Pet*_*rey 5

当你使用next()它时,读取下一个单词.你的第一行有两个单词CareyBlem#ITA#6#---#4m49.8.当您从一行读取单词时,您需要使用它nextLine()来转到下一行.

我怀疑你真正想要的是什么

Scanner sc = new Scanner(scFile.nextLine()).useDelimiter("#");
Run Code Online (Sandbox Code Playgroud)

一次读一整行.