A property in Java can be used to store a value and associate that value with a key. A common application of properties is storing user preferences. For example, a nickname can be stored in a properties file and retrieved at a later time by using a key of "nickName". To learn how to work with properties in Java, follow these four steps.
Propertiesobject is instantiated at line 10. The individual property values entered by the user are stored on the file that is created when instantiating a
FileOutputStreamobject (line 11). The
storemethod is used to write the properties to the file. The program then reads the properties by creating a
FileInputStreamobject and loads the properties object from the file using the
loadmethod. The program echoes the values to the console. Change the string literals containing the path name of the file (
c:/JavaStuff) to a path that exists on your computer.