JAVA之序列化A
2024-08-31 05:31:39
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
最新文章
- ReactNative入门(安卓)——API(上)
- [git]解决:git config --global push.default matching
- Android通过URL加载网络图片
- C# Windows Service服务的创建和调试
- python中并行遍历:zip和map-转
- [r]How To Use Git To Create A Key
- Python学习笔记 (3) :列表、元组的操作
- jmeter 压测最近的心得体会
- configure: error: no acceptable C compiler found in $PATH 问题解决
- MySQL创建数据库与用户
- OpenStack的八年之痒
- 解决Hibernate:could not initialize proxy - no Session(申明:来源于网络)
- day0315 迭代器
- 输入一串字符,检查是否可以组成friend
- Log4j将不同Package的日志输出到不同的文件的方法
- TeeChart的网络资料
- HUE配置文件hue.ini 的hbase模块详解(图文详解)(分HA集群和非HA集群)
- Python学习笔记——与爬虫相关的网络知识
- uwsgi错误invalid request block size
- Informatica PowerCenter下载地址
热门文章
- 用canvas把图片变成黑白相片
- jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法
- 去除TFS版本控制信息
- PHP 发布两个不用递归的树形数组构造函数(转)
- Swift: 类与结构体
- AS 2.0新功能 Instant Run
- poj 1811 Pallor Rho +Miller Rabin
- try{...} catch {...} finally{...} 各种情况代码的执行情况
- LINQ的基本用法
- 招行ODC项目表彰