会出现问题,因为我希望从文本文件中生成标签,然后将其放入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发布于 2017-04-06 18:21:18
您的扫描器正在读取字符串"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!");
}https://stackoverflow.com/questions/43249984
复制相似问题