Properties: setProperty(String key, String value) : Properties « java.util « Java by API






Properties: setProperty(String key, String value)

 


import java.io.FileOutputStream;
import java.util.Properties;

public class Main {
  public static void main(String[] args) throws Exception {
    Properties properties = new Properties();
    properties.setProperty("database.type", "mysql");
    properties.setProperty("database.url", "jdbc:mysql://localhost/mydb");
    properties.setProperty("database.username", "root");
    properties.setProperty("database.password", "root");

    FileOutputStream fos = new FileOutputStream("database-configuration.xml");
    properties.storeToXML(fos, "Database Configuration", "UTF-8");
  }
}
 

   
  








Related examples in the same category

1.new Properties()
2.new Properties(Properties prop)
3.Properties: getProperty(String key)
4.Properties: getProperty(String key, String defaultValue)
5.Properties: list(PrintStream out)
6.Properties: load(InputStream inStream)
7.Properties: loadFromXML(InputStream in)
8.Properties: keySet()
9.Properties: propertyNames()
10.Properties: store(OutputStream out, String comments)
11.Properties: storeToXML(OutputStream os, String comment)