Properties is the sub-class of Hashtable class. Properties class object is used for reading of maintaining system environmental variables and reading the data from resource data file or properties file.
Properties ();
public void setProperty (Object kobj, Object vobj); public Object getProperty (Object kobj); public void load (InputStream);
Write a java program which illustrates the concept of Properties class?
Answer:
import java.util.*; import java.io.*; class properties { public static void main(String[] args) { try { Properties p = new Properties(); FileInputStream fis = new FileInputStream("x.prop"); p.load(fis); Object vobj1 = p.get("dno"); Object vobj2 = p.get("dname"); Object vobj3 = p.get("pwd"); System.out.println("USER NAME :" + vobj2); System.out.println("DEPT NUMBER : " + vobj1); System.out.println("PASSWORD : " + vobj3); } catch (Exception e) { System.out.println(e); } } };