如何使用HashMap编写和读取文件? [英] How to write and read a file with a HashMap?

查看:119
本文介绍了如何使用HashMap编写和读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 HashMap 与两个字符串 Map< String,String> ldapContent = new HashMap< String,String>



现在我要将Map保存在外部文件中,以便稍后使用Map,而不进行初始化再次...



所以我该如何安全地图再次使用它?

解决方案

HashMap 实现可序列化,以便您可以使用正常的序列化将hashmap写入文件

以下是 Java - 序列化示例的链接


I've a HashMap with two Strings Map<String, String> ldapContent = new HashMap<String, String>.

Now I want to save the Map in a external file for use the Map later without initialize it again...

So how I must safe the Map to use it later again?

解决方案

HashMap implements Serializable so you can use normal serialization to write hashmap to file

Here is the link for Java - Serialization example

这篇关于如何使用HashMap编写和读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆