Sort answer: Learn how to use the Serializable interface in Java
Long answer:
I can only assume that you want to implement save data, correct? I recommend that you learn how to implement the Serializable interface. It's basically a way to write objects to a file. You could make a class that takes in properties and retrieves properties like...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| SaveData sd = SaveData.getSaveData("saveFile.txt") if(sd == null) { sd = new SaveData(); }
sd.addProperty("hasBanana", "true"); sd.save("saveFile.txt"); if(sd.getProperty("hasBanana").equals("true")) { eatBanana(); } |
Of course, you'll have to write the SaveData class yourself, but if you wanted to save data for more complicated objects, it is possible. For instance...
1
| sd.addProperty("inventory", playerInventory); |
Keep in mind that it takes some work to property implement the Serializable interface. Basically, you'll be adding many Serializable objects that you want to save to an instance of the Serializable class, SaveData. Then, you can easily write a SaveData to a file.
It is not THAT simple and you should definitely look up how to property use the Serializable interface.
Just remember that you need an ObjectOutputStream to write an Object to a file, and ObjectInputStream to read an Object from a file, and all object being written must implement the Serializable interface.
Oh, and just so you know, there are other ways to write Objects to a file besides using java's built in Serializable interface. Just felt like mentioning this so no one on this site yells at me.