package SwingGui.sky.com;
import java.io.*;

public class GameSaverTest {
    public static void main(String[] args) {
        GameCharacter one = new GameCharacter(50, "Elf", new String[] {"bow", "sword", "dust"});
        GameCharacter two = new GameCharacter(200, "Troll", new String[] {"bare hands", "bix ax"});
        GameCharacter three = new GameCharacter(120, "Magician", new String[] {"spells", "invisibility"});

        try {
            ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("Game.ser"));
            os.writeObject(one);
            os.writeObject(two);
            os.writeObject(three);
            os.close();
        } catch(IOException ex) {
            ex.printStackTrace();
        }
        one = null;
        two = null;
        three = null;

        try {
            ObjectInputStream is = new ObjectInputStream(new FileInputStream("Game.ser"));
            GameCharacter oneRestore = (GameCharacter) is.readObject();
            GameCharacter twoRestore = (GameCharacter) is.readObject();
            GameCharacter threeRestore = (GameCharacter) is.readObject();

            System.out.println("One's type: " + oneRestore.getType());
            System.out.println("Two's type: " + twoRestore.getType());
            System.out.println("Three's type: " + threeRestore.getType());
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }

}

package SwingGui.sky.com;
import java.io.*;

public class GameCharacter implements Serializable {
    int power;
    String type;
    String[] weapons;
    public GameCharacter(int p, String t, String[] w) {
        power = p;
        type = t;
        weapons = w;
    }

    public int getPower() {
        return power;
    }
    public String getType() {
        return type;
    }
    public String getWeapons() {
        String weaponList = "";

        for (int i = 0; i < weapons.length; i++) {
            weaponList += weapons[i] + " ";
        }
        return weaponList;
    }

}

Game.ser内容(基本看不明白):

 sr SwingGui.sky.com.GameCharacter酭锕?胅 I powerL typet Ljava/lang/String;[ weaponst [Ljava/lang/String;xp 2t Elfur [Ljava.lang.String;V玳{G xp t bowt swordt dustsq ~ 萾 Trolluq ~ t
bare handst bix axsq ~ xt Magicianuq ~ t spellst invisibility

最新文章

  1. ReactNative入门(安卓)——API(上)
  2. [git]解决:git config --global push.default matching
  3. Android通过URL加载网络图片
  4. C# Windows Service服务的创建和调试
  5. python中并行遍历:zip和map-转
  6. [r]How To Use Git To Create A Key
  7. Python学习笔记 (3) :列表、元组的操作
  8. jmeter 压测最近的心得体会
  9. configure: error: no acceptable C compiler found in $PATH 问题解决
  10. MySQL创建数据库与用户
  11. OpenStack的八年之痒
  12. 解决Hibernate:could not initialize proxy - no Session(申明:来源于网络)
  13. day0315 迭代器
  14. 输入一串字符,检查是否可以组成friend
  15. Log4j将不同Package的日志输出到不同的文件的方法
  16. TeeChart的网络资料
  17. HUE配置文件hue.ini 的hbase模块详解(图文详解)(分HA集群和非HA集群)
  18. Python学习笔记——与爬虫相关的网络知识
  19. uwsgi错误invalid request block size
  20. Informatica PowerCenter下载地址

热门文章

  1. 用canvas把图片变成黑白相片
  2. jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法
  3. 去除TFS版本控制信息
  4. PHP 发布两个不用递归的树形数组构造函数(转)
  5. Swift: 类与结构体
  6. AS 2.0新功能 Instant Run
  7. poj 1811 Pallor Rho +Miller Rabin
  8. try{...} catch {...} finally{...} 各种情况代码的执行情况
  9. LINQ的基本用法
  10. 招行ODC项目表彰