Program to Convert Property file to Xml File in java

We will read from c:/ and convert it to c:/MyXmlFile.xml

c:/ looks like this >
#This is MyPropertyFile
#Wed Aug 26 18:32:05 IST 2015

Program to Convert Property file to Xml File in java >

import java.util.Properties;
/** */
public class ConvertPropertyToXmlFile {
public static void main(String[] args) throws IOException {
     String propFileName = "c:/";
     // 1) Create FileInputStream
     FileInputStream fis = new FileInputStream(propFileName);
     // 2) Create java.util.Properties and load from FileInputStream
     Properties prop = new Properties();
     String xmlFileName = "c:/MyXmlFile.xml";
     // 3) Create Xml file
     FileOutputStream fos = new FileOutputStream(xmlFileName);
     prop.storeToXML(fos, "Dynamic Property File");
     System.out.println(xmlFileName + " has been created from "
              + propFileName);
c:/MyXmlFile.xml has been created from c:/

c:/MyXmlFile.xml will look like this >
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "">
<comment>Dynamic Property File</comment>
<entry key="Language">Java</entry>
<entry key="myName">Ankit</entry>

For more convenience below I have attached screenshot as well.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
//start paginationJs //end paginationJs