0

会出现问题,因为我想从文本文件中制作标签,然后将其放入 VBOX,我得到 inputmismatchexception 并且它不制作新对象

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
4

1 回答 1

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!");
}
于 2017-04-06T18:21:18.267 回答