If the data that you want to save is going to be highly decoupled from the rest of the world, then one of the easiest ways to save/load data is to use the built in serialize function. Basically, it writes out all of the data from the object, including information about its class, then allows it to be read back in at a later date.
By highly decoupled, I mean that you could take the data and remove it from its context without damaging the information. Example:
public class Character {
static final long serialVersionUID = -6618469841127325812L; //Serialization ID, required to ensure that the file is recognized as being this class if changes happen.
private int currentX;
private int currentY;
private int currentHealth;
private int currentExp;
private int currentWorldId;
private transient World currentWorld;
We have enough information there, I would hope, that you can not completely save the ‘currentWorld’ field to the disc and could, instead, use the currentWorldId to help restore. Anything you don’t want to save would be marked with the transient keyword. If you need to save data about your world, then you’d remove the transient and then blah, blah, blah.
This is made much easier if you only allow saving at certain points (Think the Metroid games or old school RPGs where you could handle most state data with the character information then a bunch of flags).
There is a caveat though, that saving data like this is somewhat problematic if you change the class and attempt to reload the data there’s a chance it won’t work correctly, however using the serialVersionUID field will help with this.