1

I want to save my Hashmap data to File by using this code:

File file = new File(getDir("data", MODE_PRIVATE), "map");    
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
outputStream.writeObject(map);
outputStream.flush();
outputStream.close();

The problem is, I don't know how to read that File and convert it back to the hashmap. How can this be done?

user207421
  • 305,947
  • 44
  • 307
  • 483
Alexa289
  • 8,089
  • 10
  • 74
  • 178
  • please provide the data after u save to files – shadow Sep 26 '19 at 10:53
  • @shadow Please provide it why? It's standard Java Serialization. The data is as per the Object Serialization Specification, Protocol chapter – user207421 Sep 27 '19 at 02:11
  • @user207421 oh,i just want to see the result cause i think it will need to read byte to byte to get the data.i just watch your solution in the link and it kinda thing i never did before.thanks u.:) – shadow Sep 27 '19 at 03:12
  • what i know is FileInputStream and FileOutputStream.Object input stream is pretty good tho.but i think the answer should put the try catch into it.cause maybe when cast the object,it might throw a exception – shadow Sep 27 '19 at 03:14

0 Answers0