You start with a xml file that you'll read with the fileInputStream.




Original xml file


Rhyme.xml




Java Code


The file is read into the fileInputStream, again it's all API work from here. just call loadFromXML() and the compiler does the rest.


package com.camelcode;
 
import java.io.FileInputStream;
import java.util.Properties;
 
public class XmlToProperties {
 
    public static void main(String args[]) throws Exception {
 
        Properties properties = new Properties();
 
        FileInputStream fis = new FileInputStream("Rhyme.xml");
        properties.loadFromXML(fis);
        properties.list(System.out);
 
        System.out.print("\n");
        System.out.println("The one-two rhyme: " + properties.getProperty("one-two"));
    }
}


Output


Output from the console.


-- listing properties --
seven-eight=lay them straight
five-six=pick up sticks
nine-ten=a big, fat hen
three-four=shut the door
one-two=buckle my shoe
 
The one-two rhyme: buckle my shoe


Download


Download source code - Convert-xml-file-into-properties-file.zip  2 KB