User Guide Cancel

SetPropertyString

 

Description 

Adds a list or collection of key-value pairs to the specified properties file. If the file is not present, the file will be created. 

Returns 

None 

Syntax 

setPropertyString(String filePath, String key, Object value, String encoding)

History 

  • ColdFusion (2025 release): Added the function 

Parameters 

Parameter

 

 

Required

 

 

Type

 

 

Description

 

 

filePath 

 

 

Yes 

 

 

String 

 

 

The absolute path of the properties file. 

 

 

key 

 

 

Yes 

 

 

String 

 

 

The key to add in the properties file. 

 

 

value 

 

 

No 

 

 

Any object 

 

 

The value for the specified key to be added in the properties file. 

 

 

encoding 

 

 

No 

 

 

String 

 

 

The encoding of the properties file. The default is UTF-8. If not specified, picks the default encoding. 

 

 

 

Example 

<cfscript>
//setPropertyString with key and value
path =GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties"
setPropertyString(path,"host","localhost","utf-8");
property1=getPropertyString(path,"host");
if (property1 EQ "localhost") {
writeOutput("Successfully set key");
}
else {
writeOutput("Failed to set key");
}
</cfscript>
<cfscript> //setPropertyString with key and value path =GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties" setPropertyString(path,"host","localhost","utf-8"); property1=getPropertyString(path,"host"); if (property1 EQ "localhost") { writeOutput("Successfully set key"); } else { writeOutput("Failed to set key"); } </cfscript>
<cfscript>
    //setPropertyString with key and value
    path =GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties"
    setPropertyString(path,"host","localhost","utf-8");
    property1=getPropertyString(path,"host");
    if (property1 EQ "localhost") {
        writeOutput("Successfully set key");
    } 
    else {
        writeOutput("Failed to set key");
    }
</cfscript>

Output

Successfully set key

Get help faster and easier

New user?