Java – Saving Properties as XML

Using storeToXML() option Property files can be stored as XML.


import java.util.Properties;

public class SavePropertyAsXML {

	public static void main(String[] args) {
		// make new instance of properties
		Properties prop = new Properties();
		// set the property values
		prop.setProperty("name", "Naveen");
		prop.setProperty("country", "US");

		// check to see if the file already exists
		File file = new File("c://install//userdetails.xml");
		if (!file.exists()) {
			// save the properties
			try {
				prop.storeToXML(new FileOutputStream(file),
						"testing properties with xml");
			} catch (IOException e) {


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "">
<comment>testing properties with xml</comment>
<entry key="name">Naveen</entry>
<entry key="country">US</entry>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s