java map如何序列化_java中map集合反序列化

这篇博客探讨了Java中对象序列化的过程,通过示例展示了如何使用ObjectOutputStream将Map对象写入文件。文章详细解释了如何将Map的键(Integer类型)和值(包含多个Goods对象的List)序列化到文件。同时,博主提出了反序列化的疑问,询问如何从文件中读取并还原原始的Map结构。
摘要由CSDN通过智能技术生成

ObjectOutputStreamout=null;try{out=newObjectOutputStream(newFileOutputStream("D:/file/project"));for(Map.Entry>entry:map.entrySet()){Integernum2=entry...

ObjectOutputStream out = null;

try {

out = new ObjectOutputStream(

new FileOutputStream("D:/file/project"));

for(Map.Entry> entry:map.entrySet()){

Integer num2 = entry.getKey();

out.writeInt(num2);

List list = entry.getValue();

for(Iterator it = list.iterator();it.hasNext();){

Goods goods = it.next();

out.writeObject(goods);

}

}

out.flush();

} catch (Exception e) {

e.printStackTrace();

} finally{

if(out != null){

try {

out.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

如何反序列化啊!跪求!

public class Goods implements Serializable{

private String goodsCode;

private String goodsName;

private double price;

public Goods(){}

public Goods(String goodsCode,String goodsName,double price){

this.goodsCode = goodsCode;

this.goodsName = goodsName;

this.price = price;

}

Goods类这些属性,还有一些没复制,反序列化,怎么读出来map的键和值?

展开

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值