Java Properties Save saveProperties(Properties props, File location)

Here you can find the source of saveProperties(Properties props, File location)

Description

Save a Properties object to a path.

License

Open Source License

Parameter

Parameter Description
props The properties object to save.
location The location to save the properties to.

Exception

Parameter Description
IOException If the file is not writable

Declaration

public static void saveProperties(Properties props, File location) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;
import java.util.*;

public class Main {
    /**/*  ww w. j av  a  2s.com*/
     * Save a {@link Properties} object to a path.
     * @param props The properties object to save.
     * @param location The location to save the properties to.
     * @throws IOException If the file is not writable
     */
    public static void saveProperties(Properties props, File location) throws IOException {
        PrintStream os = new PrintStream(new FileOutputStream(location.getAbsolutePath()));
        List<String> keys = new ArrayList<>(props.stringPropertyNames());
        Collections.sort(keys);
        for (Object key : keys) {
            os.println(key.toString() + " = " + props.get(key).toString());
        }
        os.close();
    }
}

Related

  1. saveProperties(Properties properties, File propertyFile)
  2. saveProperties(Properties properties, File propFile, String propertiesName)
  3. saveProperties(Properties properties, String fileName, String header)
  4. saveProperties(Properties properties, String filePath)
  5. saveProperties(Properties properties, String propertiesFileName, String header)
  6. saveProperties(String fileName, Properties properties)
  7. saveProperties(String fileName, Properties properties, String title)
  8. saveProperties(String propName, Properties props)
  9. savePropertiesToEncodedString(Properties props, String comment)