read and write key/value in .properties file

.properties is a file extension for files mainly used in Java related technologies to store the configurable parameters of an application. the parameters are in terms of key value pair, means we can use the key in the code to get the value stored in the .properties file.
This basically helps to avoid going to the code for any change needed in the value, we can directly change in the file itself.
An example: Open a notepad, enter key and values and “Save As” – “”
Normally in framework, we use .properties file to store Username, Password, URL under test, browser type / version, platform etc…
it helps each automation tester to use their own details in program and also helps to keep their credentials confidential.
Let’s understand more about the .properties file!


  • [key] = [value] or [key] : [value]
  • For comments, statements starts with either ! or #.
  • White space at beginning or before and after of = or : are ignored.
  • Blank lines are ignored.
  • If value is written in multi line, then each line should be ended with ” (backslash).
Let’s see the code to read the values(MethodName-getVal()) from the key/variable we entered in the .properties file and how to update/write values to the keys(MethodName-setVal()).

Out Put:

Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *