Tutorialspoint examples

Learn java tutorial with examples for beginners online

store property file as xml file java program


Example:

package com.tutorialspointexamples;
 
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", "tutorialspointexamples@gmail.com");
      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.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status