Jump to content

How to get property value from config.properties file


Recommended Posts

Hello

config.properites file

browser = chrome


LoadConfig.java file

public class LoadConfig{
	public static String BrowserType = null;

	public static boolean load() throws Exception {
		Properties envProps = new Properties();
		envProps.load(new FileInputStream(ConfigFile));
		BrowserType = envProps.getProperty("browserType"); // it should get the value from config.properties file
		
}
}

 

Test

public static void main(String[] args) throws IOException {
System.out.println(LoadConfig.BrowserType);
}

I get null when I run my main method instead I like to see the value "chrome" from the config.properties file. How can I get the value of chrome when I run main method?

Link to comment
Share on other sites

You have to call the load() method at least once before you can access the properties.

LoadConfig.load();
System.out.println(LoadConfig.BrowserType);

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...