我有一个包含大量条目的哈希映射,它是序列化的。如果我在哈希映射中做了一个小改动,它是否需要我完全覆盖旧文件或者是否存在替代方案?Java更新数据结构更改为序列化文件
public class HashMapSerial {
public static void main(String[] args) {
HashMap<String,Integer> hash=new HashMap<String, Integer>(100000);
hash.put("hello",1);
hash.put("world", 2);
//+ (100000 -2) entry's
ObjectOutputStream s=new ObjectOutputStream(new FileOutputStream(new File("hash.out")));
s.writeObject(hash); // write the hash map to file
hash.put("hello",10);
s.writeObject(hash); //rewrite the whole hashmap again
}
}
由于更改仅对字符串“hello”,并没有其他因素,才有可能更新序列化的文件只为字符串“hello”,而不是再一次改写整个HashMap的?