Here you can find the source of saveToFile(Properties prop, String fileName)
public static void saveToFile(Properties prop, String fileName)
//package com.java2s; //License from project: Apache License import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Properties; public class Main { public static void saveToFile(Properties prop, String fileName) { try {/*from w w w .ja v a 2s . c o m*/ FileOutputStream fileOutput = new FileOutputStream(fileName); OutputStreamWriter writer = new OutputStreamWriter(fileOutput, "ISO-8859-1"); Enumeration propNames = prop.propertyNames(); List keys = new ArrayList(); while (propNames.hasMoreElements()) { keys.add(propNames.nextElement()); } Collections.sort(keys); for (int i = 0; i < keys.size(); i++) { String key = (String) keys.get(i); writer.write(key); writer.write(" = "); writer.write(prop.getProperty(key)); writer.write("\n"); } writer.flush(); writer.close(); fileOutput.close(); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException("Unexpected exception! caused by: " + e.getMessage(), e); } } }