Pin It

A simple program demonstrating how to store properties to an XML file ?

A simple program demonstrating how to store properties to an XML file

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;


public class StoreXmlDemo {
 
   public static void main(String[] args) {
  
 String file = "customer.xml";
  
 // Create a FileOutputStream by providing
 // name of file 
 FileOutputStream fis;
 try {
           fis = new FileOutputStream(file);
  
    // Create a Properties Object
    Properties properties = new Properties();
    // Set few properties on it 
           properties.setProperty("firstname", "Jonty");
           properties.setProperty("lastname", "Magicman");
           properties.setProperty("email", "Jonty@magic.com");
           // After setting properties, try to store in the xml
           // by calling storeToXML() method
    properties.storeToXML(fis, "CustomerInfo", "UTF-16");
 
 } catch (FileNotFoundException e) {
   
  e.printStackTrace();
 } catch (IOException e) {
   
  e.printStackTrace();
 }
   }

}




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