Java Properties save and load to XML file

Description

Java Properties save and load to XML file

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

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

    p.put("Key", new Date().toString());
    p.put("user", "CSS");

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

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

    p.loadFromXML(in);/*w  w w  . j av  a2s .  c  o  m*/
    p.list(System.out);
  }
}



PreviousNext

Related