当我使用带有IBM JDK7的ObjectInputStream时,我得到了异常:
java.io.StreamCorruptedException: invalid type code: F1
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1712)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2397)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2277)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2179)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1684)
at java.io.ObjectInputStream.readObjectImpl(ObjectInputStream.java:531)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:466)
但是,当我使用IBM的JDK6或oracle的JDK运行代码时,一切正常! 问题出在哪儿?一些代码如:
String str = "";
ObjectInputStream in = null;
String hStr = "0123456789ABCDEF";
ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length() / 2);
for (int i = 0; i < str.length(); i += 2) {
baos.write((hStr.indexOf(str.charAt(i)) << 4 | hStr.indexOf(str.charAt(i + 1))));
}
byte[] bytes = baos.toByteArray();
in = new ObjectInputStream(new ByteArrayInputStream(bytes));
in.readObject();//this line Throws ”StreamCorruptedException: invalid type code: F1“