我想測試一個程序,並且我需要訪問ReadExternal函數,但是我在ObjectInputStream上發生了StreamCorrupted異常。 我知道我需要使用的writeObject寫入的對象,但不知道該怎麼辦呢?當通過ObjectInputStream反序列化時發生StreamCorruptedException
ObjectOutputStream out=new ObjectOutputStream(new ByteArrayOutputStream());
out.writeObject(ss3);
ss3.writeExternal(out);
try{
ByteInputStream bi=new ByteInputStream();
bi.setBuf(bb);
out.write(bb);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bb));
String s1=(String) in.readObject();
}
catch(Exception e){
e.printStackTrace();
}
你能提供一個簡單的,你自己想要做的自包含的例子嗎?您不應該直接調用read/writeExternal,因爲它們被對象流使用。 –
這是什麼'bb'?正如彼得所說,一個簡短但完整的程序真的會有所幫助。 –