Java Properties Save saveProps(Properties p, String fname, String comment)

Here you can find the source of saveProps(Properties p, String fname, String comment)

Description

save Props

License

Open Source License

Declaration

public static void saveProps(Properties p, String fname, String comment) throws IOException 

Method Source Code

//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();
    }
}

Related

  1. savePropertiesToEncodedString(Properties props, String comment)
  2. savePropertiesToString(Properties props, String comment)
  3. saveProperty(String key, String value)
  4. saveProperty(String key, String value)
  5. saveProperty(String key, String value)
  6. saveProps(String path, Properties props)
  7. saveSorted(Properties props, File file)
  8. saveSysDirProperties(Properties sysProps, String classpathDirectory)
  9. saveToFile(Properties prop, String fileName)