Pin It

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 : 






Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot