将一个静态对象分别写入两个不同的流中,然后分别又读出来,但是却得到的是不同的对象呢,对象写入到流中的到底是什么呢?
------最佳解决方案--------------------------------------------------------
反序列化创建的对象当然会不同,就算value一样,hashcode也不同的。
------其他解决方案--------------------------------------------------------
肿么不来人哇哇。。。
------其他解决方案--------------------------------------------------------
无代码无真相
------其他解决方案--------------------------------------------------------
class TO implements Serializable{
static TO tt= new TO();
}
public class ObjectStream {
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("object.txt"));
ObjectOutputStream os2 = new ObjectOutputStream(new FileOutputStream("object2.txt"));
ObjectInputStream is=new ObjectInputStream(new FileInputStream("object.txt"));
ObjectInputStream is2=new ObjectInputStream(new FileInputStream("object2.txt"));
os.writeObject(TO.tt);
os2.writeObject(TO.tt);
TO bb=(TO)is.readObject();
TO cc=(TO)is2.readObject();
System.out.println(bb==cc);
is.close();
os.close();
is2.close();
os2.close();
}
}
------其他解决方案--------------------------------------------------------
那为什么同一个对象写入一个流中,然后读出来的对象是一样的呢?
你说的不是太懂,能说的具体点吗?
到底对象写入文件中的是什么呢?
------其他解决方案--------------------------------------------------------
代码如四楼。