Properties file is being used commonly in every project to get external or supported parameters like configurations, urls, port numbers and ids etc. We can handle these files using file stream APIs like FileInputStream, FileOutputStream etc, provided in java by treating these files as normal text files. But another way is also there to handle the property files, which is the best and efficient way to handle these by using the API java.util.Properties . The class Properties has few methods on which the below are very important and most useful. load(InputStream in): To load the external properties file loadFromXML(InputStream in): To load an XML file as a property file getProperty(String key): To read value of a property key from the property file getProperty(String key,String defaultValue): To read value of a property key from the property file. If the key doesn’t exist then it will return the defaultValue. Let us see an example to understand how to use the Properties class. Create a pr...
A better way to be wealthy in the future