Whatever message this page gives is out now! Go check it out!

GetPropertyString

Last update:
May 18, 2026

Description

Retrieves the value of a key that is defined in a properties file.

Returns

The value of the key.

Syntax

getPropertyString(String filePath, String key, 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
A key defined in the properties file.
encoding
No
String
The encoding of the properties file. The default is UTF-8.

Example

Example 1
<cfscript> 
    path =GetDirectoryFromPath(GetCurrentTemplatePath()) & "test.properties" 
    property1=getPropertyString(path,"appname"); 
    property2=getPropertyString(path,"port"); 
    property3=getPropertyString(path,"smtpserver"); 
    writeDump(property1) 
    writeDump(property2) 
    writeDump(property3) 
</cfscript>
Output
SampleApp 5432 smtp.example.com
Example 2- with encoding
<cfscript>
    path =GetDirectoryFromPath(GetCurrentTemplatePath()) & "test.properties"
    property1=getPropertyString(path,"app.name","UTF-8");
    property2=getPropertyString(path,"port","UTF-8");
    property3=getPropertyString(path,"smtp.server","UTF-8");
    writeDump(property1)
    writeDump(property2)
    writeDump(property3)
</cfscript>
Output
SampleApp 5432 smtp.example.com
Example 3- Empty key
<cfscript>
    //Empty Key
    try {
        path = GetDirectoryFromPath(GetCurrentTemplatePath()) & "test.properties";
        // Ensure that the function getPropertyString is defined or imported properly
        property1 = getPropertyString(path,"");
    } 
    catch (any e) {
        writeOutput(e.message);
    }
</cfscript>
Output
"Key cannot be empty"
Example 4- key not present or invalid key
<cfscript>
    //key not present or invalid key
    try {
        path = GetDirectoryFromPath(GetCurrentTemplatePath()) & "test.properties";
        // Ensure that the function getPropertyString is defined or imported properly
        property1 = getPropertyString(path,"invalid.name");  
        writeDump(property1)      
    } 
    catch (any e) {
        writeOutput(e.message);
    }
</cfscript>
Output
[empty string]

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page