Convert properties file into XML file
- Read a XML file with DOM
- Create XML file with DOM
- Delete XML nodes with DOM
- Read a XML file with SAX
- JAX-B Marshal
- JAX-B Unmarshal
- Convert properties file into XML file
- Convert XML file into properties file
- XPath tutorial
- From XML to JSON
- Convert properties file into XML file
- Convert XML file into properties file
Comments (0)
Many developers may not aware of this function, actually, the java.util.Properties class come with a storeToXML()method to convert existing properties data into a XML file.
Java Code
To convert the properties file to xml file is really ease, just call: storeToXML()
package com.camelcode;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
public class PropertiesToXml {
public static void main(String[] args) throws IOException {
Properties prop = new Properties();
prop.setProperty("one-two", "buckle my shoe");
prop.setProperty("three-four", "shut the door");
prop.setProperty("five-six", "pick up sticks");
prop.setProperty("seven-eight", "lay them straight");
prop.setProperty("nine-ten", "a big, fat hen");
OutputStream os = new FileOutputStream("Rhyme.xml");
prop.storeToXML(os, "Rhyme","UTF-8");
System.out.println("Rhyme created");
}
}
Generated file
The file that's been generated





Latest Posts
Latest Comments
Tag cloud