在 Java 中,我得到了这个异常:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at com.reading.text.Activity3.readFile(Activity3.java:22)
at com.reading.text.Activity3.main(Activity3.java:10)
从此Java代码:
public static void main(String args[])
{
readFile("C:/Users/forsakendoll/Desktop/boom.txt");
}
public static void readFile(String path) {
Scanner file = null;
try {
file = new Scanner(new File (path));
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
while (file.hasNext()) {
for(int counter = 0 ; counter < file.next().length(); counter ++) {
System.out.println(file.next().charAt(counter));
}
}
}
}
抛出异常
System.out.println(file.next().charAt(counter));
异常是什么意思?