本帖最后由 张向辉 于 2013-2-5 12:22 编辑  
 
import java.io.*; 
 
class ObjectStreamDemo  
{ 
        public static void main(String[] args) throws Exception 
        { 
                //writeObj(); 
                readObj(); 
        } 
        public static void readObj()throws Exception 
        { 
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream("obj.txt")); 
 
                Person p = (Person)ois.readObject(); 
 
                System.out.println(p);// 这里打印结果是lisi: 23  问题:为什么这里打印的是对象中的内容,而不是对象的内存地址呢?               
                ois.close(); 
        } 
 
 
        public static void writeObj()throws IOException 
        { 
                ObjectOutputStream oos =  
                        new ObjectOutputStream(new FileOutputStream("obj.txt")); 
 
                oos.writeObject(new Person("lisi0",399,"kr")); 
 
                oos.close(); 
} 
 
} |   
        
 
    
    
    
     
 
 |