Use XML with PropertiesTag(s): Language XML


import java.util.*;
import java.io.*;

class XMLProps {
  public static void main(String args[]) {
    new XMLProps().doit();
  }

  public void doit() {
    try{
      Properties p = new Properties();

      p.put("today", new Date().toString());
      p.put("user", "Bob");

      FileOutputStream out = new FileOutputStream("user.props");
      p.storeToXML(out,"props updated");

      FileInputStream in = new FileInputStream("user.props");

      p.loadFromXML(in);
      p.list(System.out);
      /*
        output :
         -- listing properties --
         today=Thu Aug 09 22:45:11 EDT 2007
         user=Bob
      */
    }
    catch (Exception e) {
      e.printStackTrace();
    }
 }
}
The XML looks like
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>props updated</comment>
<entry key="user">Bob</entry>
<entry key="today">Thu Aug 09 22:45:11 EDT 2007</entry>
</properties>

blog comments powered by Disqus