Java Properties Save saveProperties(String fileName, Properties properties, String title)

Here you can find the source of saveProperties(String fileName, Properties properties, String title)

Description

save Properties

License

Open Source License

Declaration

final static public void saveProperties(String fileName, Properties properties, String title) 

Method Source Code


//package com.java2s;

import java.io.BufferedOutputStream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Main {
    private static String fUserHome = System.getProperty("user.home");
    private static char fFileSeparator = System.getProperty("file.separator").charAt(0);
    private static char fLastCharOfDirectory = fUserHome.charAt(fUserHome.length() - 1);

    final static public void saveProperties(String fileName, Properties properties, String title) {
        try {//from w w  w.  ja  va 2  s. c  om
            FileOutputStream fos = new FileOutputStream(makeFullPathname(fileName));
            BufferedOutputStream bos = new BufferedOutputStream(fos);

            properties.store(bos, title);
            bos.close();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static public String makeFullPathname(String fileName) {
        if (fLastCharOfDirectory == fFileSeparator)
            return fUserHome + fileName;
        else
            return fUserHome + fFileSeparator + fileName;
    }
}

Related

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