Java Properties Save saveProperties(Properties properties, File propertiesFile, String comments)

Here you can find the source of saveProperties(Properties properties, File propertiesFile, String comments)

Description

Save data from a Properties object into some .properties file

License

Open Source License

Parameter

Parameter Description
properties Properties with data to save
propertiesFile File of the <code>.properties</code> file to save
comments Some description to be located as comment at the beginning of the content of the file

Exception

Parameter Description
IOException Error while writing the file

Declaration

public static void saveProperties(Properties properties, File propertiesFile, String comments)
        throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source 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 ww  w.  j  a  va 2s. c  om
     * Save data from a Properties object into some <code>.properties</code> file
     *
     * @param properties     {@link Properties} with data to save
     * @param propertiesFile {@link File} of the <code>.properties</code> file to save
     * @param comments       Some description to be located as comment at the beginning of the
     *                       content of the file
     * @throws IOException Error while writing the file
     */
    public static void saveProperties(Properties properties, File propertiesFile, String comments)
            throws IOException {
        if (!(propertiesFile.exists() && propertiesFile.isFile())) {
            propertiesFile.createNewFile();
        }

        try (OutputStream out = new FileOutputStream(propertiesFile)) {
            properties.store(out, comments);
        }
    }
}

Related

  1. saveProperties(Map map, Writer tmpWriter)
  2. saveProperties(Properties p, String file)
  3. saveProperties(Properties p, String sFile)
  4. saveProperties(Properties prop, String fileName, String remark)
  5. saveProperties(Properties properties, File file)
  6. saveProperties(Properties properties, File propertyFile)
  7. saveProperties(Properties properties, File propFile, String propertiesName)
  8. saveProperties(Properties properties, String fileName, String header)
  9. saveProperties(Properties properties, String filePath)