>That would be awesome Ben. I playing around with your code at the moment but
>I doubt I'll be able to do much with it this weekend (kids to look after and
>all that!!)
>
>Plus the fact it's dinnertime!!
>
>Cheers
>
>Will

Will,

here's what I use to read in a JNDI properties file. Its fairly standard stuff 
so feel free to modify it as you need to.

hth,
larry

<cffunction name="openAndReadFile" access="public" output="false"
  returntype="struct">

  <cfargument name="readThisFile" type="string">

  <cfscript>
    var fileReader = "";
    var fileAsString = "";
    var bufferedReader = "";

    variables.fileContentsStructure = structNew();
        
    fileReader = createObject("java", "java.io.FileReader");
    fileReader.init(passedInFile);
    bufferedReader = createObject("java", "java.io.BufferedReader");
    bufferedReader.init(fileReader);
    try {
        do {
            fileAsString = bufferedReader.readLine();
            processLine(fileAsString);
        } while (true);
    } catch (coldfusion.runtime.UndefinedVariableException e) {
    // this indicates end of file, ok to ignore error 
    } 
    return variables.fileContentsStructure;
    </cfscript>
</cffunction>

<cffunction name="processLine" access="private" output="false"  
    hint="process individual lines and put them into 
          an structure called variables.fileContentsStructure">
    <cfargument name="line" required="true">
    <cfset var varName = "">
    <cfset varValue = "">
    <cfif not structKeyExists(variables,"fileContentsStructure")>
        <cfset variables.fileContentsStructure = structNew()>
    </cfif>
    <cfif not find("##",arguments.line)>
        <!--- ## is used to comment out a line in the target file ignore --->
        <cfset varName = listFirst(arguments.line, "=")>
        <cfset varValue = listLast(arguments.line, "=")>
        <cfset  variables.fileContentsStructure[varname] = varValue>
    </cfif>
</cffunction>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:264252
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to