Abuse was faster, anyway:
There are multiple options to do this. A common way is to use Properties
, where you need to put in the values.
Another option would be Serialization
, which is a bit more comfortable, since you don't have to convert your variables from and to a string representation. On the downside, the written files normally aren't human readable.
If your class containing the variables follow java bean pattern (having public getter and setter methods), you can use Bean XML Serialization
, which produces a human readable xml file. If you don't want to bother and are willing to use a third party library, you can use XStream
, which allows very easy persistance of arbitrary java objects to xml files. Under more complex circumstances you might save your whole memory, though
There is also the Java Architexture for XML Binding
, but this may be a bit of an overkill...