class TestStruct implements java.io.Serializable
{
     public int a = 3;
     public String s = "ss";
}

解决方案 »

  1.   

    // :)
    ObjectOutputStream oos_test;
    oos_test.writeObject(new TestStruct());
      

  2.   

    //write
    import java.io.*;
    import java.util.*;public class serial1
    {
     public static void main(String args[])
     {
      Map hm=new HashMap();
      hm.put("Mary","123-4567");
      hm.put("Larry","234-5678");
      hm.put("Mary","456-7890");
      hm.put("Felicia","345-6789");
     
      try{
      FileOutputStream fos= new FileOutputStream("test.ser");
    ObjectOutputStream oos =new ObjectOutputStream(fos);
    oos.writeObject(hm);
    oos.close();
      }
      catch(Throwable e){
     System.err.println(e);
      }
     } 
    }//read
    import java.io.*;
    import java.util.*;public class serial2
    {
     public static void main(String args[])
     {
    Map hm=null;
    try{
      FileInputStream fis=new FileInputStream("test.ser");
    ObjectInputStream ois=new ObjectInputStream(fis);
    hm=(Map)ois.readObject();
        ois.close();
    }
    catch(Throwable e){
      System.err.println(e);
    }
    if(hm!=null){
     Iterator iter=hm.entrySet().iterator();
     while(iter.hasNext()){
    Map.Entry e=(Map.Entry)iter.next();
    System.out.println(e.getKey()+" "+e.getValue());
     }
      }
     }
    }
      

  3.   

    jiaojian77(长夜漫漫) 大侠:
        谢谢你得顷力相助,但我想知道得是如何远程之间传递一个类。(其实我得真正用意是想做一个SOCKET一方是JAVA程序,另一方是C++程序,他们之间互相传递结构体,所以我想先弄明白JAVA是怎么传递一个类得?)
        谢谢大家鼎力相助,
        希望大家给一个传递类(发送和接收)得小例子,或主要代码!
    谢谢!
      

  4.   

    kucao(枯草) :
    我也在做--SOCKET一方是JAVA程序,另一方是C++程序
    不如把心得贴出来大家共享一下,谢谢!!