マニュアル キャンセル

GetPropertyString

 

説明

プロパティファイルで定義されているキーの値を取得します。 

戻り値

キーの値。 

シンタックス

getPropertyString(String filePath, String key, String encoding)

履歴

  • ColdFusion(2025 リリース):関数が追加されました

パラメーター

パラメーター

 

 

必須

 

 

Type

 

 

説明

 

 

filePath

 

 

はい

 

 

文字列

 

 

プロパティファイルの絶対パス。 

 

 

key

 

 

はい

 

 

文字列

 

 

プロパティファイルで定義されたキー。 

 

 

encoding

 

 

いいえ

 

 

文字列

 

 

プロパティファイルのエンコード。デフォルトは UTF-8 です。 

 

 

例 1

<cfscript>
path =GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;
property1=getPropertyString(path,&quot;appname&quot;);
property2=getPropertyString(path,&quot;port&quot;);
property3=getPropertyString(path,&quot;smtpserver&quot;);
writeDump(property1)
writeDump(property2)
writeDump(property3)
</cfscript>
<cfscript> path =GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot; property1=getPropertyString(path,&quot;appname&quot;); property2=getPropertyString(path,&quot;port&quot;); property3=getPropertyString(path,&quot;smtpserver&quot;); writeDump(property1) writeDump(property2) writeDump(property3) </cfscript>
<cfscript> 
    path =GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot; 
    property1=getPropertyString(path,&quot;appname&quot;); 
    property2=getPropertyString(path,&quot;port&quot;); 
    property3=getPropertyString(path,&quot;smtpserver&quot;); 
    writeDump(property1) 
    writeDump(property2) 
    writeDump(property3) 
</cfscript>

出力

SampleApp 5432 smtp.example.com

例 2 - エンコードの使用

<cfscript>
path =GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;
property1=getPropertyString(path,&quot;app.name&quot;,&quot;UTF-8&quot;);
property2=getPropertyString(path,&quot;port&quot;,&quot;UTF-8&quot;);
property3=getPropertyString(path,&quot;smtp.server&quot;,&quot;UTF-8&quot;);
writeDump(property1)
writeDump(property2)
writeDump(property3)
</cfscript>
<cfscript> path =GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot; property1=getPropertyString(path,&quot;app.name&quot;,&quot;UTF-8&quot;); property2=getPropertyString(path,&quot;port&quot;,&quot;UTF-8&quot;); property3=getPropertyString(path,&quot;smtp.server&quot;,&quot;UTF-8&quot;); writeDump(property1) writeDump(property2) writeDump(property3) </cfscript>
<cfscript>
    path =GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;
    property1=getPropertyString(path,&quot;app.name&quot;,&quot;UTF-8&quot;);
    property2=getPropertyString(path,&quot;port&quot;,&quot;UTF-8&quot;);
    property3=getPropertyString(path,&quot;smtp.server&quot;,&quot;UTF-8&quot;);
    writeDump(property1)
    writeDump(property2)
    writeDump(property3)
</cfscript>

出力

SampleApp 5432 smtp.example.com

例 3 - 空のキー

<cfscript>
//空のキー
try {
path = GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;;
// getPropertyString 関数が適切に定義または読み込まれていることを確認します
property1 = getPropertyString(path,&quot;&quot;);
}
catch (any e) {
writeOutput(e.message);
}
</cfscript>
<cfscript> //空のキー try { path = GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;; // getPropertyString 関数が適切に定義または読み込まれていることを確認します property1 = getPropertyString(path,&quot;&quot;); } catch (any e) { writeOutput(e.message); } </cfscript>
<cfscript>
    //空のキー
    try {
        path = GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;;
        // getPropertyString 関数が適切に定義または読み込まれていることを確認します
        property1 = getPropertyString(path,&quot;&quot;);
    } 
    catch (any e) {
        writeOutput(e.message);
    }
</cfscript>

出力

「キーを空にすることはできません」

例 4 - キーが存在しないか無効なキー

<cfscript>
//キーが存在しないか、無効なキーです
try {
path = GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;;
// getPropertyString 関数が適切に定義または読み込まれていることを確認します
property1 = getPropertyString(path,&quot;invalid.name&quot;);
writeDump(property1)
}
catch (any e) {
writeOutput(e.message);
}
</cfscript>
<cfscript> //キーが存在しないか、無効なキーです try { path = GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;; // getPropertyString 関数が適切に定義または読み込まれていることを確認します property1 = getPropertyString(path,&quot;invalid.name&quot;); writeDump(property1) } catch (any e) { writeOutput(e.message); } </cfscript>
<cfscript>
    //キーが存在しないか、無効なキーです
    try {
        path = GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;test.properties&quot;;
        // getPropertyString 関数が適切に定義または読み込まれていることを確認します
        property1 = getPropertyString(path,&quot;invalid.name&quot;);  
        writeDump(property1)      
    } 
    catch (any e) {
        writeOutput(e.message);
    }
</cfscript>

出力

[空の文字列]

ヘルプをすばやく簡単に入手

新規ユーザーの場合

Acrobat 購入相談

Acrobat 購入相談

Acrobat 購入相談

Acrobat 購入相談