Java Utililty Methods Properties Save

List of utility methods to do Properties Save

Description

The list of methods to do Properties Save are organized into topic(s).

Method

voidsaveProperties(Properties properties, String propertiesFileName, String header)
Save properties to a specified file.
FileOutputStream propertiesFile = new FileOutputStream(propertiesFileName);
properties.store(propertiesFile, header);
propertiesFile.flush();
propertiesFile.close();
voidsaveProperties(Properties props, File location)
Save a Properties object to a path.
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();
booleansaveProperties(String fileName, Properties properties)
save Properties
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(fileName);
    properties.store(fos, null);
} catch (FileNotFoundException ex) {
    System.out.println("The server configuration properties file not exists");
} catch (IOException ioe) {
    System.out.println("The property file configuration wrintng error");
...
voidsaveProperties(String fileName, Properties properties, String title)
save Properties
try {
    FileOutputStream fos = new FileOutputStream(makeFullPathname(fileName));
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    properties.store(bos, title);
    bos.close();
    fos.close();
} catch (IOException e) {
    e.printStackTrace();
...
voidsaveProperties(String propName, Properties props)
save a properties file
try {
    FileOutputStream fs = new FileOutputStream(propName);
    props.store(fs, null);
} catch (RuntimeException ex) 
    throw ex;
} catch (IOException ex) 
    throw new IllegalArgumentException("Cannot save properties to " + propName);
StringsavePropertiesToEncodedString(Properties props, String comment)
save Properties To Encoded String
if (props == null)
    return null;
return encodeName(savePropertiesToString(props, comment));
StringsavePropertiesToString(Properties props, String comment)
save Properties To String
if (props == null)
    return null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
props.store(out, comment);
String tmpString = out.toString();
out = null;
return tmpString;
voidsaveProperty(String key, String value)
save Property
if (mProperties == null)
    mProperties = new Properties();
createFile();
try (OutputStream lOutputStream = new FileOutputStream(FILE_NAME)) {
    mProperties.put(key, value);
    mProperties.store(lOutputStream, null);
} catch (IOException e) {
    throw e;
...
voidsaveProperty(String key, String value)
save Property
Properties prop = getProperties();
OutputStream output = null;
try {
    output = new FileOutputStream("config.properties");
    prop.setProperty(key, value);
    prop.store(output, null);
} catch (IOException io) {
    io.printStackTrace();
...
voidsaveProperty(String key, String value)
save Property
Properties properties = loadUserSettings();
properties.setProperty(key, value);
saveUserSettings(properties);