我想讀取已輸出到.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