A simple program demonstrating how to store properties to an XML file
Output of the program :
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 :
