setPropertyString

Sets one key, or several keys from a struct, in a Java properties file. Existing keys are updated, new keys are added, and other keys are kept. The file is rewritten with a #File created by CF comment and a timestamp at the top.

setPropertyString(filepath, key, value [, encoding]) setPropertyString(filepath, properties) → returns void

Argument Reference

filepath string
Required

Absolute path to the properties file.

key string

The key to set. Not used when passing a properties struct.

value string

The value to set for key.

encoding string
Default: utf-8

Character encoding of the file.

properties struct

A struct of keys and values to set. Pass it as the second argument instead of key and value.

Compatibility

ColdFusion:

Version 2025+ Listed by getFunctionList() in ColdFusion 2025+. No official documentation exists. Signature and behavior confirmed on CF2025.

Lucee:

Version 7.0.0.108+ Lucee only supports the key and value syntax, not the properties struct.

Examples
Sample code invoking the setPropertyString function

path = getTempDirectory() & "app.properties";
fileWrite(path, "a=1");
setPropertyString(path, "b", "hello");
writeOutput(getPropertyString(path, "b"));

Expected Result: hello

path = getTempDirectory() & "app.properties";
fileWrite(path, "a=1");
setPropertyString(path, {"a": "9", "c": "3"});
writeOutput(serializeJSON(getPropertyFile(path)));

Expected Result: {"a":"9","c":"3"}

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub