Mark Reddy bio photo

Mark Reddy

Modern Java programmer with an interest in distributed systems

Twitter Google+ LinkedIn Instagram Github

Many developers may not aware that the java.util.Properties class comes with a storeToXML() method to convert existing properties data into a XML file.

import java.util.Properties;
public class PropertiesXMLExample
    public static void main(String[] args) throws IOException
        Properties props = new Properties();
        props.setProperty("", "");
        //where to store?
        OutputStream os = new FileOutputStream("c:/email-configuration.xml");
        //store the properties detail into a pre-defined XML file
        props.storeToXML(os, "Support Email","UTF-8");

The above example will write the properties detail into a XML file “c:/email-configuration.xml“.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "">
        <comment>Support Email</comment>
        <entry key=""></entry>