Why Properties file?

To hide sensitive information of the projects we save the information in properties file.

To configure Properties file, create a new file and save as with .properties extension. Now add the data in following manner in Properties file:

URL=http://www.google.com
INT_USR=msrivastava
INT_PWD=Hello123&

Now use below lines of code to read this property file-

try{
FileInputStream prop = new FileInputStream (“D:\\Selenium_Projects\\Property\\setup.properties”);
Properties a = new Properties ();
try {
a.load(prop);
} catch (IOException e) {

e.printStackTrace();
}
String URL=a.getProperty(“URL”);
String USR=a.getProperty(“INT_USR”);
String PWD=a.getProperty(“INT_PWD”);
System.out.println(URL);
System.out.println(USR);
System.out.println(PWD);
}catch (FileNotFoundException e){
e.printStackTrace();
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s