I find this to be a lot simpler, here is a class I made: Code: package your.package.name import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.logging.Logger; import org.bukkit.plugin.java.JavaPlugin; public class SaveLoad { //by cowboys1919.. public static boolean save(JavaPlugin plugin, Object o, String fileName, Logger l, boolean defaultFolder) { if (defaultFolder) { fileName = plugin.getDataFolder()+"/"+fileName; } try { SaveLoad.save(o, plugin.getDataFolder()+"/"+fileName); l.info("Saved '"+fileName+"'"); return true; } catch (Exception e) { l.severe("Could not save stats data to '"+fileName+"'"); l.severe(e.getMessage()); return false; } } public static boolean save(JavaPlugin plugin, Object o, String fileName, Logger l) { return save(plugin, o, fileName, l, true); } public static Object loadDat(JavaPlugin plugin, String fileName, Logger l, boolean defaultFolder) { if (defaultFolder) { fileName = plugin.getDataFolder()+"/"+fileName; } if (new File(fileName).exists()) { try { l.info("Loaded '"+fileName+"' file."); return SaveLoad.open(fileName); } catch (Exception e) { l.severe("[SEVERE]Could not load '"+fileName+"' file."); l.severe(e.getMessage()); return null; } } else { l.info("No '"+fileName+"' file exists, a new object should be made here."); return null; } } public static Object loadDat(JavaPlugin plugin, String fileName, Logger l) { return loadDat(plugin, fileName, l, true); } private static void save(Object obj, String filePath) throws Exception { ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(filePath)); stream.writeObject(obj); stream.flush(); stream.close(); } private static Object open(String filePath) throws Exception { ObjectInputStream stream = new ObjectInputStream(new FileInputStream(filePath)); Object result = stream.readObject(); stream.close(); return result; } } Then to use add a serializable field to your class Code: public HashMap<String, Boolean>CoolPlayers; In onEnable() Code: CoolPlayers = (HashMap<String, Boolean>)SaveLoad.load(this, "coolPlayers.dat", getLogger()); if (CoolPlayers == null) //if it's empty CoolPlayers = new HashMap<String, Boolean>; Modify it somewhere. Code: CoolPlayers.put("Cowboys1919", true); Then in onDisable() Code: if (SaveLoad.save(this, CoolPlayers, "coolPlayer.dat", getLogger())) //Sucess else //Uhm, failure Have fun, don't worry about crediting me but do if you like
Sagacious_Zed So, not exactly sure what to do. Do you mean i should make the save and open not throw exception and handle it from within there and close inside of finally because if there is a problem it may not make it there or something?
No, you have to make sure that the streams are closed, and the only way to make sure of that is in a finally block.
HASHMAP?!?!?!? NUUU awdagdiuaowdh w *rage* awudtaowdyaoyda I use my own API. Thank you for viewing my opinion of this wonderful API.