store property file as xml file java

Example:

package com.w3spoint;
 
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Properties;
 
public class XMLPropertyFileTest {
  public static void main(String args[]){
      OutputStream os = null;
      Properties prop = new Properties();
      prop.setProperty("name", "tutorialspointexamples");
      prop.setProperty("domain", "www.tutorialspointexamples.com");
      prop.setProperty("email", "[email protected]");
      try {
          os = new FileOutputStream("TestProp.properties");
          prop.storeToXML(os, "Dynamic Property File");
          System.out.println("XML Property file created successfully.");
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
}

Output:

TestProp.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>Dynamic Property File</comment>
<entry key="email">tutorialspointexamples@gmail.com</entry>
<entry key="name">tutorialspointexamples</entry>
<entry key="domain">www.tutorialspointexamples.com</entry>
</properties>

Download this example.

Please follow and like us:
Content Protection by DMCA.com