How to convert XML file into properties file - Java XML Tutorial

In the last article, we show you how to convert properties file into an XML file. See following XML file :

1. INPUT: user.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE properties SYSTEM ""><properties><comment>user detail</comment><entry key="email"></entry><entry key="username">admin</entry></properties>

2. Function Details:

Loads all of the properties represented by the XML document on the specified input stream into this properties table.

public void loadFromXML(InputStream in)                 throws IOException,                        InvalidPropertiesFormatException


package com.example.TestApp;import;import;import;import java.util.Properties;public class XMLFile2PropertieFile { public static void main(String[] args) throws IOException {           InputStream os = new FileInputStream("/Users/admin/Desktop/user.xml");    Properties properties = new Properties();    properties.loadFromXML(os);    String username = properties.getProperty("username");    String email = properties.getProperty("email");    System.out.println("username: " + username + "\n" + "email: " + email); }}


username: adminemail: