Example usage for java.util Properties Properties

List of usage examples for java.util Properties Properties

Introduction

In this page you can find the example usage for java.util Properties Properties.

Prototype

public Properties() 

Source Link

Document

Creates an empty property list with no default values.

Usage

From source file:Main.java

public static void main(String[] a) throws Exception {
    Properties p = new Properties();
    URL url = ClassLoader.getSystemResource("/com/java2s/config/system.props");
    if (url != null)
        p.load(url.openStream());//from w w  w .  ja  va 2s  .c  o  m

}

From source file:Main.java

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");
  }//w  w  w.ja  va2  s  .  c o  m

From source file:Main.java

public static void main(String args[]) throws Exception {
    Properties props = new Properties();

    props = new java.util.Properties();
    String path = new Main().getClass().getProtectionDomain().getCodeSource().getLocation().toString()
            .substring(6);// w ww  .j a v  a2  s. com
    FileInputStream fis = new FileInputStream(new File(path + "\\myprops.props"));
    props.load(fis);
    System.out.println(props);

}

From source file:MainClass.java

public static void main(String args[]) {
    Properties prop = new Properties();
    prop.put("a", "1");
    prop.put("b", "2");
    prop.put("c", "3");
    Properties book = new Properties(prop);
    book.put("A", "4");
    book.put("B", "5");

    System.out.println("a " + book.getProperty("a"));
    System.out.println("A " + book.getProperty("b"));
    System.out.println("c: " + book.getProperty("c"));

    System.out.println("z: " + book.getProperty("z", "default"));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Properties config = new Properties();
    config.load(new FileInputStream("conf-file.pros"));

    Enumeration en = config.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        System.out.println(key + ":" + config.get(key));
    }/*from w  ww. j  a va 2  s  .co m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Properties properties = new Properties();
    try {//from www.j  a  v a2 s.  co m
        properties.load(new FileInputStream("filename.properties"));
    } catch (IOException e) {
    }
    String string = properties.getProperty("a.b");
    properties.setProperty("a.b", "new value");
}

From source file:Main.java

public static void main(String[] args) {
    Properties properties = new Properties();

    properties.setProperty("name", "Designer");
    properties.setProperty("version", "1.0");
    properties.setProperty("vendor", "Inc");

    Map<String, String> map = new HashMap<String, String>((Map) properties);

    Set propertySet = map.entrySet();
    for (Object o : propertySet) {
        Map.Entry entry = (Map.Entry) o;
        System.out.printf("%s = %s%n", entry.getKey(), entry.getValue());
    }//from w  w  w  . j  a v  a  2  s .  c om
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Properties p = new Properties();
    p.load(new FileInputStream("test.txt"));
    Enumeration e = p.propertyNames();

    for (; e.hasMoreElements();) {
        System.out.println(e.nextElement());

    }//w  w  w .j  av  a2s . co m
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    Properties props = new Properties();
    URL url = ClassLoader.getSystemResource("myprops.props");
    props.load(url.openStream());/*from   w  w  w .  j  a v a2s.c  o  m*/
    System.out.println(props);

}

From source file:Main.java

public static void main(String args[]) {

    Properties prop = new Properties();

    prop.setProperty("A", "t@h.com");
    prop.setProperty("B", "k@h.com");
    prop.setProperty("C", "R@h.com");
    prop.setProperty("D", "S@h.com");

    HashMap<String, String> propMap = new HashMap<String, String>((Map) prop);

    Set<Map.Entry<String, String>> propSet;
    propSet = propMap.entrySet();/*from   w  w w  .ja  v a  2s  . c  o  m*/

    System.out.println("Contents of map: ");
    for (Map.Entry<String, String> me : propSet) {
        System.out.print(me.getKey() + ": ");
        System.out.println(me.getValue());
    }
}