Properties in Java

Properties  in Java

Properties in Java is a subclass of  Hashtable.It stores String values against String keys.The contents of a  Properties object  can be directly saved to  a file and a properties file can be  directly  loaded to a properties object.Since Properties  is a subclass of Hashtable,  the methods put() and putAll()  is applicable to Properties too. These methods allow the insertion of non-String keys as well as values.So the use of put() and putAll() is highly discouraged.

The program shown below reads a properties file and displays the key value pairs.The appending few more keys.The existing myfile.properties file is in C:/tmp folder.

 

Now see the code shown below.

Output

Contents of properties

Key : TN ; Value : Chennai

Key : Goa ; Value : Panaji

Key : Kerala ; Value : Trivandrum

Reading is over

Added  new properties

Contents of properties

Key : Karnataka ; Value : Bangalore

Key : TN ; Value : Chennai

Key : Goa ; Value : Panaji

Key : Bihar ; Value : Patna

Key : Kerala ; Value : Trivandrum

Reading is over

Tagged with 

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">