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 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 :




 
© 2021 Learn Java by Examples Template by Hubberspot