While the cffile tags are extremely useful they are a bit of a resource hog because they load the actual file into memory. ColdFusion 8 brings new file functions that interact with the file system directly. Last week I saw just how much faster and leaner using these functions is. I needed to loop over a 155,000 line file, do a regular expression on the line and append it to a new file.
Doing this with cffile action="append" I could see the memory increase in the server monitor and it took on average 46 seconds. I then switched out cffile action="append" with the code below, ran it saw no memory increase in the server monitor and it took 20 seconds on average.
<cfset variables.fileobj= fileOpen("/fileLocation/OnYourcomputer/FileName.txt", "append" )> <cfset fileWriteLine(variables.fileObj,"" )> <cfset fileClose(variables.fileobj)>
Notice how in the fileOpen function I set the mode to append. Oh, and I was also using cfloop file="" with this which interacts directly with the file and makes looping over files easy.