private void readWords() throws IOException {
initialCt = readFrom("C:\\Curses1.txt", initialWords);
midCt = readFrom("C:\\Curses2.txt", middleWords);
endCt = readFrom("C:\\Curses3.txt", endingWords);
} // readWords()
// Pre: fileName is the name of an input file. Tokens (items) in the
// file are strings separated by whitespace.
// Pre: wordList has been allocated and is large enough to hold all
// the tokens in the input file.
// Post: wordList contains all the tokens in the input file, one token
// per string.
private int readFrom(String fileName, String[] wordList) throws IOException {
int count= 0;
FileInputStream fstream = new FileInputStream(fileName);
Scanner scan2 = new Scanner (fstream);
while (scan2.hasNext()){
initialWords[count] =scan2.nextLine();
middleWords[count] = scan2.nextLine();
endingWords [count] = scan2.nextLine();
String words = scan2.next();
++count;
}
return count;
} // readFrom()
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at Curses.readFrom(Curses.java:95)
at Curses.readWords(Curses.java:63)
at Curses.run(Curses.java:51)
at Curses.main(Curses.java:131)
我正在尝试读取三个不同的文本文件并将它们的值存储在三个不同的数组中,但 java 找不到该文件。这只是类的一部分,但这是发生错误的地方。任何帮助将不胜感激!