Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

A simple program demonstrating how to load properties from an xml file ?

A simple program demonstrating how to load properties from an xml file

import java.io.FileInputStream;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;


public class LoadXmlDemo {
 
   public static void main(String[] args) {
  
 LoadXmlDemo load = new LoadXmlDemo();
 
 Properties properties = load.getProperties();
 String email = properties.getProperty("email");
 String firstname = properties.getProperty("firstname");
 String lastname = properties.getProperty("lastname");
  
 System.out.println("Email of the Customer : " + email);
 System.out.println("Firstname of the Customer : " + firstname);
 System.out.println("Lastname of the Customer : " + lastname);

   }
 
   public Properties getProperties() {
 Properties prop = new Properties();
 try {
            FileInputStream fis = new FileInputStream("Customer.xml");
      
     prop.loadFromXML(fis);
   
 } catch (InvalidPropertiesFormatException e) {
   
    e.printStackTrace();
 } catch (IOException e) {
   
    e.printStackTrace();
 }
 return prop;
   }
}



XML file used to load properties :













Output of the program : 






 
© 2021 Learn Java by Examples Template by Hubberspot