文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>java-序列化

java-序列化

时间:2010-07-27  来源:cj_gameboy

import java.io.*;

class MyClass implements Serializable{
    String a;
    int b;
    double c;
    MyClass(String a, int b, double c){
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public String toString(){
        return "a="+a+";b="+b+";c="+c;
    }
};
public class test {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception{
        // TODO Auto-generated method stub

        try{
            MyClass object1 = new MyClass("Hello", -7, 2.7);
            FileOutputStream fos = new FileOutputStream("serial");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(object1);
            oos.close();
        }catch(Exception e){
            System.out.println("err");
        }
        
        try{
            MyClass object2;
            FileInputStream fis = new FileInputStream("serial");
            ObjectInputStream ois = new ObjectInputStream(fis);
            object2 = (MyClass)ois.readObject();
            ois.close();
            System.out.println("Object2:"+object2);
        }catch(Exception e){
            System.out.println("err");
        }
    }
    
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载