JavaFX InputMismatchException - 来自扫描仪的标签

JavaFX InputMismatchException - Label from Scanner

会出现问题,因为我想从文本文件制作标签,然后将其放入 VBOX,我收到输入不匹配异常,但它不会制作新对象

VBox vertikalBox = new VBox();
try (Scanner s = new Scanner("rebricek.txt")) {
        while (s.hasNext()) {
            //InputMismatchException 
            vertikalBox.getChildren().addAll(new Label(""+ s.nextInt() + " " + s.next() + " " + s.nextInt()));
            s.nextLine();
        }


    } catch (Throwable t) {
        // inputmismatchexception - PROBLEM
        // this is for NoSuchElementException
        System.err.println("Vyskytla sa chyba pri praci zo suborom");
    }

文件内容:

1 nikto 10
2 nikto 0
3 nikto 0
4 nikto 0
5 nikto 0
6 nikto 0
7 nikto 0
8 nikto 0
9 nikto 0
10 nikto 0

您的扫描仪正在读取字符串 "rebrickek.txt" 而不是文件

File file = new File("rebricek.txt");

if(file.exist())
{
    Scanner s = new Scanner(file);
    .
    .
    .
}
else
{
    System.out.println("The file does note exist!");
}