User Guide Cancel

GetPropertyFile

 

Description

Retrieves all the key-value pairs in the specified properties file.

Returns

Struct of the key-value pairs in the properties file. 

Syntax

getPropertyFile(String filePath, String encoding)

History

  • ColdFusion (2025 release): Added the function 

Parameters

Parameter

 

 

Required

 

 

Type

 

 

Description

 

 

filePath

 

 

Yes

 

 

String 

 

 

The absolute path of 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

Example 1

<cfscript>
path =GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties"
properties=getPropertyFile(path);
writeDump(properties)
</cfscript>
<cfscript> path =GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties" properties=getPropertyFile(path); writeDump(properties) </cfscript>
<cfscript>
    path =GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties"
    properties=getPropertyFile(path);
    writeDump(properties)
</cfscript>

Example 2- invalid encoding

<cfscript>
//incorrect enconding format
try {
path = GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties";
property1 = getPropertyFile(path,"ISO-8859-1121");
writeDump(property1)
}
catch (any e) {
writeOutput(e.message);
}
</cfscript>
<cfscript> //incorrect enconding format try { path = GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties"; property1 = getPropertyFile(path,"ISO-8859-1121"); writeDump(property1) } catch (any e) { writeOutput(e.message); } </cfscript>
<cfscript>
    //incorrect enconding format
    try {
        path = GetDirectoryFromPath(GetCurrentTemplatePath()) & "config.properties";
        property1 = getPropertyFile(path,"ISO-8859-1121");
        writeDump(property1)
    } 
    catch (any e) {
    writeOutput(e.message);
    }
</cfscript>

Get help faster and easier

New user?