Skip to content

Commit 8bc8d84

Browse files
committed
feat(ReadXMLUsingPropertieClass): add demo for reading XML configuration with Properties
What - Added ReadXMLUsingPropertieClass in Package2. - Uses java.util.Properties to load key-value pairs from an XML file. - Prints entire Properties object and retrieves value for key `"Name: "`. Why - Demonstrates how to load configuration stored in XML format. - Complements previous examples using `.properties` files and `storeToXML()`. - Useful when config needs structured storage or integration with XML tools. How - Created new Properties object. - Called loadFromXML(FileInputStream) to parse XML file into Properties. • XML must follow the DTD defined by Properties (keys/values as `<entry>` elements). - Accessed individual property using getProperty("Name: "). - Printed full Properties map to console. Logic - loadFromXML reads standard Java Properties XML format: <properties> <comment>...</comment> <entry key="Name: ">Value</entry> </properties> - Keys and values remain Strings. - If the key is not found, getProperty() returns null. - Unlike `.properties` files, encoding is always UTF-8 for XML. Real-life applications - Store user preferences, metadata, or app settings in XML form. - Easier integration with XML-based configuration systems. - Better readability and extensibility compared to flat `.properties` files. - Common in apps where configuration must be both human-readable and tool-friendly. Summary - ReadXMLUsingPropertieClass shows loading settings from an XML file into Properties. - Demonstrates retrieving both all entries and a specific key. - Highlights Properties versatility: supports both `.properties` (text) and `.xml` formats. Signed-off-by: https://github.com/Someshdiwan <someshdiwan369@gmail.com>
1 parent 6f222e7 commit 8bc8d84

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • Section23JavaIOStreams/Properties/src/Package2

Section25CollectionFramework/src/Properties/Person.xml renamed to Section23JavaIOStreams/Properties/src/Package2/Person.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Person Properties New File For reading using JAVA Program.
66
How to read XML file using Properties in JAVA program.
77
</comment>
8-
<entry key="Name: ">Donald</entry>
9-
<entry key="Age: ">99</entry>
10-
<entry key="Address: ">LA</entry>
8+
<entry key="Name: ">Jackson</entry>
9+
<entry key="Age: ">80</entry>
10+
<entry key="Address: ">SF</entry>
1111
<entry key="Country: ">USA</entry>
1212
</properties>

0 commit comments

Comments
 (0)