Java Arraylist 程序抛出 NoSuchElementException

我的程序应该接受任何数据类型的文件输入并显示它。但是在阅读第 7 个元素后,我收到错误“NoSuchElementException”

这是我的代码:

http://img3.mukewang.com/61025b070001e24e06020439.jpg

慕尼黑的夜晚无繁华
浏览 252回答 2
2回答

ibeautiful

我认为您正在尝试这样做:public static void main(String[] args) throws FileNotFoundException {&nbsp; &nbsp; Scanner in = new Scanner(new FileReader("input.text"));&nbsp; &nbsp; List<String> arrayType = new ArrayList<>(100);&nbsp; &nbsp; List<String> linkedType = new LinkedList<>();&nbsp; &nbsp; while (in.hasNext()){&nbsp; &nbsp; &nbsp; &nbsp; String line = in.next();&nbsp; &nbsp; &nbsp; &nbsp; arrayType.add(line);&nbsp; &nbsp; &nbsp; &nbsp; linkedType.add(line);&nbsp; &nbsp; }&nbsp; &nbsp; System.out.println(arrayType);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java