Properties to XML in java

This example shows you how to store Properties object’s key and value in XML file

Below is the example code:


import java.util.Properties;

//Properties to XML in java
public class PropertiesToXmlExample {
	public static void main(String[] args) throws Exception {
		Properties properties = new Properties();
		properties.setProperty("", "Mahendra SUDA");
		properties.setProperty("person.age", "29 years");
		properties.setProperty("person.occupation", "Software");

		FileOutputStream outputStream = new FileOutputStream(
		properties.storeToXML(outputStream, "Person xml file", "UTF-8");

The output of the generated xml file looks like as:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "">
<comment>Person xml file</comment>
<entry key="">Mahendra SUDA</entry>
<entry key="person.age">29 years</entry>
<entry key="person.occupation">Software</entry>