tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > Properties > Save XML Properties

Save XML Properties 

The following example shows storing already loaded properties into a XML file.

File Name  :  
com/bethecoder/tutorials/utils/props/StoreXMLProps.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.utils.props;

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

public class StoreXMLProps {
  /**
   @param args
   */
  public static void main(String[] args) {

    Properties prop = new Properties();
    prop.setProperty("ONE""111111");
    prop.setProperty("TWO""222222");
    prop.setProperty("THREE""333333");
    prop.setProperty("FOUR""444444");
    
    String propFile = "C:/prop_xml_file.xml";
    String comments = "My test comments";
    
    try {
      System.out.println(prop);
      prop.storeToXML(new FileOutputStream(propFile), comments);
    catch (IOException e) {
      e.printStackTrace();
    }
  }
}
   

It serializes properties to XML file.
It gives the following output,
{TWO=222222, FOUR=444444, ONE=111111, THREE=333333}



 
  


  
bl  br