我一直在看这个……我什至输入了 item = null 来看看会发生什么……但是这段代码一直卡在无限循环中。item 始终等于 null 并且应该退出循环但它会继续运行。
ArrayList<String> collection = new ArrayList();
Scanner arrayRead = new Scanner(new FileReader("SalesStar.txt"));
//iterate through file to put into Arraylist
String item = null;
while( item != null ) {
item = arrayRead.next();
collection.add(item);
}
arrayRead.close();
System.out.println(collection);
System.out.println(item);