Saving hashmap to a file

Discussion in 'Plugin Development' started by TerraPlay, Aug 22, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    TerraPlay

  2. Offline

    sddddgjd

    You can't open players.bin,it's a binary file....and are you using the SLAPI to save/load?
     
  3. Offline

    obnoxint

    Try casting the loaded Object to a Hashmap like this:
    Code:
    HashMap<String, String> result = (HashMap<String, String>)ois.readObject();
    Then return the HashMap but not as Object.

    This actually doesn't matter. It's just a name.
     
  4. Offline

    TerraPlay

    Have this now, still not working :/
    Code:
        public static HashMap<String, String> load(String path) throws Exception {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));
            HashMap<String, String> result = (HashMap<String, String>) ois.readObject();
            ois.close();
            return result;
     
  5. Offline

    obnoxint

    Ah, just saw it, look at line 39:
    Code:
    load("plugins/VisualExactSpawn/players.bin");
    You are calling the method. But what now? You don't assign the returned HashMap to the field 'JoinedPlayers'. :D

    Btw: use lowercase-camelcase for fieldnames. You can easily confuse the name with a class.
    E.g. use 'joinedPlayers' instead of 'JoinedPlayers'.
     
    TerraPlay likes this.
  6. Offline

    TerraPlay

    Obvious mistakes are obvious. It's working now, thank you very very much. :)
     
  7. Offline

    obnoxint

    You're welcome.
     
Thread Status:
Not open for further replies.

Share This Page