title: Save and read hashmap to file?
body: <p>I want to write and read this hashmap to and from a txt file. This is what i have tried:</p>
  
  <p>Main class:</p>
  
  <pre><code>    SaveRead xd = new SaveRead();
      HashMap &lt;String,Integer&gt;users = new HashMap&lt;String,Integer&gt;();
  </code></pre>
  
  <p>//e gets called on start</p>
  
  <pre><code>    private Object e() throws ClassNotFoundException, FileNotFoundException, IOException {
          return xd.readFile();
      }
  
      public void onFinish() {
            try {
              xd.saveFile(users);
          } catch (IOException e) {
          }
      }
  </code></pre>
  
  <p>//SaveRead class:</p>
  
  <pre><code>public class SaveRead implements Serializable{
  
      public void saveFile(HashMap&lt;String, Integer&gt; users) throws IOException{
      ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("/Users/Konto/Documents/scores.txt"));
      outputStream.writeObject(users);
  }
  
      public HashMap&lt;String, Integer&gt; readFile() throws ClassNotFoundException, FileNotFoundException, IOException{
          Object ii = new ObjectInputStream(new FileInputStream("/Users/Konto/Documents/scores.txt")).readObject();
          return (HashMap&lt;String, Integer&gt;) ii;
      }
  }
  </code></pre>
  
  <p>Does this seem ok? When it try to read the file i dont get the desired result. Is there any better way going about it? </p>