Man, I recently made a thread like this. I ended up implementing a HashMap and writing it to a file. I used Serializables, although apparently there are some alternatives that are more effective than Java’s built in Serialization. The save data might be something like…
public class SaveData
{
private HashMap saveData<String, Serializable>;
public void addProperty(String key, Serializable value)
{
saveData.put(key, value);
}
public void removeProperty(String key)
{
saveData.remove(key);
}
// I don't feel like writing this. Just know that you can use an ObjectOutputStream to write a Serializable object to a file, and an ObjectInputStream
// to read an object from a file. It should save the Object as it is so long as you did everything right. I recommend looking up how to use the
// Serializable Interface. In conclusion, you'd be planning to write the HashMap to a file.
public void save()
{
}
// Yeah, use an ObjectInputStream to read the HashMap into the SaveData if it exists. Otherwise, make a new HashMap
public void load()
{
}
}
Keep in mind that not everything about an object can be serialized. The attributes of an object will become Serialized along with the object so long as they either implement the Serializable Interface, or are of a primitive data type. A HashMap implements the Serializable interface, so it is fair game.
Yeah, and this code won’t run… Haven’t tested it. Just demonstrates.