• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

using randomAccessFile.readLine()

Guest
Mar 23, 2011 Mar 23, 2011

Copy link to clipboard

Copied

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.

TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

So they are actually in CF8.  I looked but must not have been looking in the right place.

I'm importing a file, but through a web interface.  So me doing it through the server doesn't help.

So I'll do some tests between CFHTTP, randomAccessFile, and CFLOOP-FILE to see which wins.  Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

In case anyone is interested...  I setup a side by side comparison, using CFHTTP (to a query, and then looping the query), RandomAccessFile, and CFLOOP-FILE to read a text file of 650,000 lines, each iterating record by record beginning to end, and captured the timestamps before and after.

RAF = 1 minute 47 seconds

CFHTTP = 37 seconds

CFLOOP = 1 second (yes, only 1)

I did a MOD on the record number, and outputed a few numbers inside the loop, just to prove to myself that it was actually iterating.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

LATEST

In case anyone is interested...  I setup a side by side

comparison

Interesting. What about BufferedReader? Not that you need it with CF8, but I am curious as I suspect that is what the I/O tags/functions use for "read" mode internally.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

I'm importing a file, but through a web interface.  So me

doing it through the server doesn't help.

As long as you can pull down the file locally, you can import it into a database. Usually running one query per line is what takes the most time/resources.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation