我不明白为什么Eclipse给我一个有关将BufferedReader返回的字符串传入哈希表的put(Object,Object)方法的错误。我读过API,我不认识任何线索。它可能不能确定它会返回一个唯一的字符串吗?不接受字符串作为键的哈希表
弦乐字典设置该文件中的其他地方,我已经剥离下来到重要的一点 - 有问题&什么方法,采用它的变量发生。
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;
public class Model {
private Hashtable hash=new Hashtable();
private String dictionary;
public void loadWords() throws IOException{
BufferedReader br=null;
try{
br=new BufferedReader(new FileReader(dictionary));
do{
hash.put(br.readLine(), new Node<E>);
}
while(br.readLine()!=null);
}catch(IOException iOE){
System.out.println("Fission mailed");
}
finally{
br.close(); // Closing the buffered reader
}
}
包括您看到的错误将有助于制定答案。 – Simes
认真你应该开始使用[ConcurrentHashMap](http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html) –
考虑:ConcurrentHashMap,Collections.synchronizedMap,[尝试与资源](http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html),[Files.readLines](http://docs.guava-libraries.googlecode.com/ git/javadoc/com/google/common/io/Files.html#readLines),[Files.readAllLines](http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files .html#readAllLines) – btiernay