Java Properties Save saveProperties(String propName, Properties props)

Here you can find the source of saveProperties(String propName, Properties props)

Description

save a properties file

License

Apache License

Parameter

Parameter Description
propName name of an existing and readable properties file

Exception

Parameter Description
IllegalArgumentException if the name is not a readable file

Declaration

public static void saveProperties(String propName, Properties props) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.util.*;

public class Main {
    /**//from w w w  . j  a  v  a  2s.  c o m
     * save a properties file
     *
     * @param propName      name of an existing and readable  properties file
     * @param propsnun-null properties file
     * @throws IllegalArgumentException if the name is not a readable file
     */
    public static void saveProperties(String propName, Properties props) throws IllegalArgumentException {
        try {
            FileOutputStream fs = new FileOutputStream(propName);
            props.store(fs, null);
        } catch (RuntimeException ex) // tempdt Why do we need this catch block?  It also is doing a poor job and not using a logger.
        {
            // ex.printStackTrace();
            throw ex;
        } catch (IOException ex) // tempdt This really isn't an IllegalArgumentException.  Dave thinks this should be fixed.  Dave can explain if desired.
        {
            throw new IllegalArgumentException("Cannot save properties to " + propName);
        }
    }
}

Related

  1. saveProperties(Properties properties, String filePath)
  2. saveProperties(Properties properties, String propertiesFileName, String header)
  3. saveProperties(Properties props, File location)
  4. saveProperties(String fileName, Properties properties)
  5. saveProperties(String fileName, Properties properties, String title)
  6. savePropertiesToEncodedString(Properties props, String comment)
  7. savePropertiesToString(Properties props, String comment)
  8. saveProperty(String key, String value)
  9. saveProperty(String key, String value)