Reading a Properties File
Property files store key-value (also called key-map) pairs in a standard format. An example of the content of such a file is:
#user information name=Ramiro familyName=Rodriguez userName=ramiroz age=37 bgColor=#000000
This is a made-up example of the properties file for an imaginary user. Note how the comment is marked using a hashtag symbol, #. You will use properties files to store the configurable parameters of applications or even for localization strings.
Let's try reading a properties file. You can create a text file in the same temporary folder that we created in the user's space earlier in the chapter. Name it user.properties
and write to it the contents of the preceding example. This follows an example of a program using java.io
to read and print out the contents of a properties file. Given the way Java works, there is no better alternative to performing this task than using java.nio
.
Note
Reading the contents of a properties...