我想读取已输出到.dat文件的多个对象(我自己的类Term),但我总是得到一个nullPointException或EOFException。阅读objectinputstream时Java中的EOFexception
ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(masterFile));
Object o = null;
while((o = inputStream.readObject()) != null){
Term t = (Term)o;
System.out.println("I found a term");
}
如果您收到EOFException,可能是因为您已达到文件末尾。 – 2010-02-22 00:39:12
是的,我认为它已经到达文件的末尾。 – user276712 2010-02-22 00:42:13
我试过这个,我只能得到EOFException。在什么情况下你会得到NullPointerException? – lins314159 2010-02-22 01:18:45