Here you can find the source of saveProps(Properties p, String fname, String comment)
public static void saveProps(Properties p, String fname, String comment) throws IOException
//package com.java2s; /*********************************************************************** Legacy Film to DVD Project//from w w w .j a v a2 s . co m Copyright (C) 2005 James F. Carroll This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ****************************************************************************/ import java.util.*; import java.io.*; public class Main { public static void saveProps(Properties p, String fname, String comment) throws IOException { FileOutputStream propertiesStream = new FileOutputStream(fname); PrintStream os = new PrintStream(propertiesStream); os.println("# " + comment); os.println(); List<String> keys = new ArrayList<String>(); for (Object c : p.keySet()) keys.add((String) c); Collections.sort(keys); for (Iterator<String> iter = keys.iterator(); iter.hasNext();) { String key = (String) iter.next(); String val = p.getProperty(key); os.println(key + "=" + val); } os.flush(); os.close(); } }