John Main Logo

John Main

Code. Design. Hosting. Maintenance.

10
Sep '11

Store the system properties in an XML file

import java.io.*;

/**
* @param fileName the file to save the properties in
*/
public void storeSystemProperties(String fileName) {
	try {
		Properties prop = System.getProperties();

		FileOutputStream fileOut = new FileOutputStream(new File(fileName));

		prop.storeToXML(fileOut, "Properties");
		fileOut.flush();
		fileOut.close();
	}
	catch(FileNotFoundException e) {
		System.out.println(e.getMessage());
	}
	catch(IOException e) {
		System.out.println(e.getMessage());
	}
}