Skip to main content
March 24, 2011
Question

using randomAccessFile.readLine()

  • March 24, 2011
  • 1 reply
  • 1399 views

I'm in CF8, and so can't take advantage of the new I/O options in CF9.  So I'm using

<cfset variables.randomAccessFile = createObject("java", "java.io.RandomAccessFile")>

<cfset line = variables.randomAccessFile.readLine()>

which works fine, until I want to do something like jump ahead to the 10,000th line.  I can put the readline() in a loop and count up to the line needed, but this is causing it to timeout.  Is there a single command something like seekLine(10000)?  I see that there is for seeking a position, character by character, but not that I can find for seeking lines.

Thanks.

This topic has been closed for replies.

1 reply

Inspiring
March 24, 2011

I'm in CF8, and so can't take advantage of the new I/O

options in CF9. 

What new options are you referring to?

seekLine(10000)?  I see that there is for seeking a

position, character by character, but not that I can find

for seeking lines.

There is no method for seeking by line. It is either jump to a specific position or read the lines one at a time.

Try a BufferedReader for comparison. Might be faster than RAF.

March 24, 2011

In CF 9, the CFLOOP with the "FILE" input, or functions like FileReadLine(), though this may just be a CF wrapper for the same Java function.

Thanks for the suggesiton.  I did just find an article that does a comparison of BufferedReader and CFHTTP to read a file to a auery, and it says the latter is much faster.  So maybe I'll give this a try.

Inspiring
March 24, 2011

In CF 9, the CFLOOP with the "FILE" input, or functions

like FileReadLine(), though this may just be a CF wrapper

for the same Java function.

Those were added in CF8, not CF9.

 

Thanks for the suggesiton.  I did just find an article

that does a comparison of BufferedReader and CFHTTP to read

a file to a auery, and it says the latter is much faster. 

So maybe I'll give this a try.

So what is your ultimate goal, importing a text file into a database? If so most have import tools that are faster than looping. Such as bulk insert in ms sql.