|
Load XML Properties
This example shows loading properties from a XML file,
|
package com.bethecoder.tutorials.utils.props;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
public class LoadXMLProps {
/**
* @param args
*/
public static void main(String[] args) {
Properties prop = new Properties();
String propFile = "C:/prop_xml_file.xml";
try {
System.out.println("Before properties load : " + prop);
prop.loadFromXML(new FileInputStream(propFile));
System.out.println("After properties load : " + prop);
//Access properties
System.out.println(prop.getProperty("ONE"));
System.out.println(prop.getProperty("TWO"));
} catch (InvalidPropertiesFormatException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
| |
XML Properties file format is shown below,
It gives the following output,
Before properties load : {}
After properties load : {TWO=222222, ONE=111111, FOUR=444444, THREE=333333}
111111
222222
|
|