Hi Martin -

I completely agree with the other comments that you should be using a DB to 
this task.  However, I wanted to mention that today I cobbled together a 
blazing fast way of reading and appending to large text files with CF + Java.

<cfscript>

  // set it to whatever file name you want (include the full path)
  myFile = myFile;

       startTime = GetTickCount();

       // init file reader and buffered reader to read file line by line
       // 'lifted' some excellent code by Greg Lively - 
http://www.informationsavvy.com/coldfusion/
       variables.joInputStreamReader = 
CreateObject("java","java.io.FileReader").init(javaCast("string", myFile));
       variables.joBufferedReader = 
CreateObject("java","java.io.BufferedReader").init(variables.joInputStreamReader,
 javaCast("int", 1024));

       initFileReaderTime = GetTickCount() - startTime;

       // create an array for appending to
       // (fastest append method in CF - see 
http://www.bennadel.com/blog/275-Passing-Arrays-By-Reference-In-ColdFusion-SWEEET-.htm)
       arrFileOut = ArrayNew(1);

       preLoopOfFileReaderTime = GetTickCount();

       // loop through until readLine() fails due to being null, which would 
throw a coldfusion.runtime.UndefinedVariableException
       // exception when setting variables.inStr = variables.inStr_good;
       isEOF = false;
       while ( not isEOF ) {
               try {
               variables.inStr_good = variables.joBufferedReader.readLine();
               variables.inStr = variables.inStr_good;
               ArrayAppend(arrFileOut, variables.inStr);
               ArrayAppend(arrFileOut, "???<br>");
               }
               catch(Any excpt) {
                  isEOF = true;
               }
       }

       loopOfFileReaderTime = GetTickCount() - preLoopOfFileReaderTime;

       // always remember to close your Java objects
       variables.joBufferedReader.close();
       variables.joInputStreamReader.close();

       totalJavaTime = GetTickCount() - startTime;

       preArrayToListTime = GetTickCount();

       // convert it back to a string
       fileOutputFromList = ArrayToList(arrFileOut, "");

       arrayToListTime = GetTickCount() - preArrayToListTime;
</cfscript>

<!--- <cfoutput>#fileOutputFromList#</cfoutput> --->

<cfoutput>initFileReaderTime: #initFileReaderTime# ms</cfoutput><br>
<cfoutput>loopOfFileReaderTime: #loopOfFileReaderTime# ms</cfoutput><br>
<!--- <cfoutput>ArrayToList time: #arrayToListTime# ms</cfoutput><br> --->
<h2><cfoutput>JAVA Reader + CF Array: #totalJavaTime# ms</cfoutput></h2>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7 
Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs 
http: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:267957
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to