Düşünebildiğim en basit çözüm, Properties sınıfını kullanmaktır.Harita yükleniyor
Map<String, String> ldapContent = new HashMap<String, String>();
Properties properties = new Properties();
for (Map.Entry<String,String> entry : ldapContent.entrySet()) {
properties.put(entry.getKey(), entry.getValue());
}
properties.store(new FileOutputStream("data.properties"), null);
:
haritası kaydediliyor
Map<String, String> ldapContent = new HashMap<String, String>();
Properties properties = new Properties();
properties.load(new FileInputStream("data.properties"));
for (String key : properties.stringPropertyNames()) {
ldapContent.put(key, properties.get(key).toString());
}
DÜZENLEME: Harita düz metin değerlerini içeriyorsa
, onlar görünür olacaktır eğer herhangi biriyle Eğer açık dosya verileri Eğer haritayı serileştirirseniz, metin editörü, böyle bir durum söz konusu değil:
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("data.ser"));
out.writeObject(ldapContent);
out.close();
EDIT2:
yerine tasarruf örnekte (OldCurmudgeon tarafından önerilen) döngü için
:
properties.putAll(ldapContent);
ancak yükleme Örneğin bu yapılabilir ki en iyisi:
ldapContent = new HashMap<Object, Object>(properties);
Ne denedi, gördünüz mü? Java serileştirme, XML, CSV, ikili veriyi manuel olarak kullanabilirsiniz ... –
Sadece basit filereader biliyorum. Bu nedenle serileştirme ipucu için teşekkür ederiz. Daha önce bilmiyorum ... –