我真的想弄清楚这段代码有什么问题。.add() 和 .toArray() 下方有红线。写这两行是否有某种替代方法?我究竟做错了什么?
package prog3;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class WordList {
private String filename;
private Word[] words;
public WordList(String fileName) {
this.filename = fileName;
}
//reads in list of words and stores them internally. line by line
//if method reas list of words successfully, then it returns as true, otherwise false
public boolean readFile() {
try{
BufferedReader read;
read = new BufferedReader(new FileReader(filename));
String nextLine;
while ((nextLine = read.readLine())!= null) {
nextLine = nextLine.trim();
read.add(new Word(nextLine));
}
words = read.toArray(new Word[0]);
}catch(IOException ex){
System.out.println("Caught exception: " +ex.getMessage());
return false;
}
return true;
}
//getList is supposed to return the list of words as an array of class Word. How do I do this???
public Word[] getList() {
}
}