dimanche 19 avril 2015

Read and write arrayList of Objects by using HashMap

I want to write and read 'HashMap' to file.


My 'HashMap' is:



Map<String, ArrayList<Descipline>> mapDis = new HashMap<String, ArrayList<Descipline>>();


and I write to file like this:



String root = Environment.getExternalStorageDirectory().toString();

Properties properties = new Properties();

for (Map.Entry<String, ArrayList<Descipline>> entry : mapDis.entrySet()){
properties.put(entry.getKey(), entry.getValue());
}

properties.store(new FileOutputStream(root + "/myMap.txt"), null);


But I don't know how to read it.



Map<String, ArrayList<Descipline>> load = new HashMap<String, ArrayList<Descipline>>();

Properties properties1 = new Properties();

properties1.load(new FileInputStream(root + "/myMap.txt"));

for (String key : properties1.stringPropertyNames()){
//something will be here to read file
}

Aucun commentaire:

Enregistrer un commentaire