Property files are common in testing, and are usually used for storing test environment data. There are various formats for property files, but they usually store data strings in key/value pairings. In order to read a property file in Java, there is a class called Properties, which has various methods that load, list, set, or get properties. Here is an example of a property file pairing, with a method to read it, for storing Selenium driver properties:
# selenium.properties file
# driver revisions
selenium.revision=3.4.0
chrome.revision=2.30
safari.revision=2.48.0
gecko.revision=0.18.0
ie.revision=3.4.0
# browser versions
firefox.browser.version=54.0
chrome.browser.version=59.0
ie.browser.version=11.0
safari.browser.version=10.0
edge.browser.version=15.15063
...
/**
* File I/O Static Utility Class
*
* @author name
*
*/
public class File_IO {
/**
* loadProps- method to load a Properties file
*
* @param file - The file to load
* @return Properties - The properties to retrieve
* @throws Exception
*/
public static Properties loadProps(String file) throws Exception {
Properties props = new Properties();
props.load(new FileInputStream(file));
return props;
}
...
// use of file I/O method loadProps
public static final String SELENIUM_PROPS = new File("../myPath/selenium.properties")
.getAbsolutePath();
Properties seProps = File_IO.loadProps(SELENIUM_PROPS);
// get properties to use
String seleniumRev = seProps.getProperty("selenium.revision"));
String firefoxVer = seProps.getProperty("firefox.browser.version"));
The JavaDoc for the Properties class is located at https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html.