Properties props = new Properties(); props.setProperty("Database URL", "jdbc:mysql://localhost/dbname"); props.setProperty("Database User", "root"); props.setProperty("Database Password", "rootpassword");
Properties props = new Properties(); try { FileInputStream input = new FileInputStream("config.properties"); props.load(input); } catch (IOException e) { e.printStackTrace(); }In this example, we have loaded the properties from a configuration file called config.properties. The FileInputStream class is used from the java.io package to read from a file. The java.util.Properties class is part of the Java Standard Library.