DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Loading An Xml Properties File

  • submit to reddit
        // simple example of loading an xml file into Properties.

Properties properties = new Properties();
try {
    InputStream xmlStream = getClass().getResourceAsStream("properties.xml");
    if( xmlStream == null ) {
         //throw some error
} catch (IOException exception) {
    // throw exception

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "">
    <entry key="plugin.TestPlugin">com.plugin.test.TestPluginModule</entry>
    <entry key="messages.TestPlugin"></entry>


Snippets Manager replied on Sun, 2007/02/11 - 4:06am

Please note that properties.loadFromXML(xmlStream) is only available Java 5 and up: Earlier Properties did not have such luxury.