幫助再次傢伙,爲什麼我總是會在使用掃描儀時出現這種錯誤,即使我確定該文件存在。沒有行發現異常
java.util.NoSuchElementException:沒有找到行
我試圖用for
循環計數的a
出現次數的數量。該文本文件包含句子的行。同時,我想打印確切的句子格式。
Scanner scanLine = new Scanner(new FileReader("C:/input.txt"));
while (scanLine.nextLine() != null) {
String textInput = scanLine.nextLine();
char[] stringArray = textInput.toCharArray();
for (char c : stringArray) {
switch (c) {
case 'a':
default:
break;
}
}
}
switch(x)對不對? – 2012-07-16 07:27:40