In this section, you will learn how to read the key-value of properties files in Java. The properties file provides the general text editor, which have the keys and it's values.
Here, you will get the key-values of the properties files according to the key with the help of this program. Program takes the file name of the properties file and it checks, if the file exists then it performs the next work Otherwise, it shows the appropriate messages like: " File not found! " and " Enter file name which has properties extension : ". This messages shows until, when your entered file name is correct. If the file name is correct then it takes the key of the properties file after that shows the appropriate key-value of the properties file. The following methods and API interfaces had been used in the program:
This is the constructor of Properties class. It extends from the Hashtable and imports form the import java.util.* package. This constructor used to create an empty property list, which hasn't any default values. The Properties class shows the persistent set of properties. It uses the Keys and key-values of the properties file. It has the load and save the properties of the properties files.
This is the method that can be used to read the keys and it's values of the properties files through the help of InputStream in the properties object. It takes the object of the InputStream.
This is the method that can be used to search the key-values of the properties file according to it's keys. This method takes the key and search the it's values in the properties list.
Here is the code of program:
Liked it! Share this Tutorial