java 文件序列化,Java序列化与纯文本文件

I'm sort of confused. Let's say I have a game that consists of some tiles and players. All these objects need to be saved so I can later start the game and restore the state. I already do this with simple files like an XML file or plain text files, where I just print the tile type and coordinates into the file and then later read, and parse and create new objects based on the information in the text file.

My question is why should I serialize my objects when I can just save their attributes to a text file? Do many games serialize their objects instea of using text files? Is there any benefit? I could imagine that serializing saves an instance of the object so that you don't have to later create a new instance of the object, like you would have to with a text file. But I really dont know!

解决方案

The main benefit of serialization in java is that you don't have to manually do the reading/writting into files, as you are doing now. You just need to implement the Serializable interface and java takes care of it.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值