Java Properties Save saveProps(String path, Properties props)

Here you can find the source of saveProps(String path, Properties props)

Description

Save properties to file.

License

Apache License

Parameter

Parameter Description
path File path.
props Properties.

Return

Success or not.

Declaration

public static boolean saveProps(String path, Properties props) 

Method Source Code


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

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStream;
import java.util.Properties;

public class Main {
    /**/*from   www.  j  av  a 2s.  c om*/
     * Save properties to file.
     * @param path File path.
     * @param props Properties.
     * @return Success or not.
     */
    public static boolean saveProps(String path, Properties props) {
        return saveProps(new File(path), props);
    }

    /**
     * Save properties to file.
     * @param file File
     * @param props Properties.
     * @return Success or not.
     */
    public static boolean saveProps(File file, Properties props) {
        OutputStream out = null;
        try {
            out = new FileOutputStream(file);
            props.store(out, null);
            return true;
        } catch (Exception e) {
            return false;
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {

                }
            }
        }
    }
}

Related

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