//Creating two properties objects Properties props1 = new Properties(); props1.setProperty("db.url", "jdbc:mysql://localhost:3306/mydb"); props1.setProperty("db.user", "root"); props1.setProperty("db.password", "secret"); Properties props2 = new Properties(); props2.putAll(props1);
//Loading properties from a file Properties props1 = new Properties(); try(InputStream input = new FileInputStream("config.properties")) { props1.load(input); } catch(IOException e) { e.printStackTrace(); } Properties props2 = new Properties(); props2.putAll(props1);In the above example, the properties are loaded from a file using FileInputStream and the load() method of Properties class. Then, the putAll() method is called to copy all the properties to another Properties object. Package library: java.util